My problem is to match IP address to its hostname.
If the IP address is a public IP then a simple socket.gethostbyaddr(ip) solves it but
my problem is with private IP i.e. IP of a network.
How can I get host names from a network IP address? Is there a way to find out hostname or not?
I'm trying to do this on Linux.
You've already got the Python code required
socket.gethostbyaddr(ip)
What you need is on the infrastructure side of things. To get an internal hostname, you need to query the internal DNS server for the network in question. Larger networks almost always have internal DNS services but some smaller network don't since they rely on other means (direct IP, NETBIOS, Bonjour, etc.) to find various resources.
TL:DR : You need to query the internal DNS services for the network in question
Related
How do I do reverse DNS lookup for a given IP?
nslookup google.com resolves to 172.217.3.46 for me.
But when I use dnspython module,
import dns.resolver
import dns.reversename
qname = dns.reversename.from_address('172.217.3.46')
answer = dns.resolver.query(qname, 'PTR')
for rr in answer:
print(rr)
>> iad23s57-in-f14.1e100.net.
>> iad23s57-in-f46.1e100.net.
I get different DNS name. How do I get google.com in this case?
Your resuts are correct. The reverse IP for the host you are querying does not point to the forward name you started with. There is no guarantee that a reverse PTR exists or that you can round-trip like you expected if one does exist.
One common scenario is HTTP multi-homing. A web server can host multiple domains; large web hosting sites commonly host hundreds of domains on each IP address they own. The reverse DNS for any random web host is statistically likely to be something like webhotel2345.hosting.example.com. rather than the name of any domain hosted there (but sometimes they just set up reverse DNS to the first one they hosted there, or the first client who complained that they want reverse DNS to check out, too).
Some mail servers are set up to reject connections from hosts whose reverse DNS does not round-trip as a (very circumstantial) anti-spam measure, but this has a fairly high rate of false positives, and is considered aggressive.
I use pyVmomi to create VM on our vCenter. We have a few networks, like 'PRD-DB'. I can change the network interface of a VM to 'PRD-DB' using pyVmomi.
I know that this network address is 10.125.10.0/24. But I can't find a way of getting this network IP address using pyVmomi. What links IPs to networks ?
[EDIT] To be more precise : How can I retrieve the list of available VLANs, that I can assign to the network card of a VM ? And can I retrieve the network addresses corresponding to these VLANs ?
Are you trying to just get the ip address for each vm?
If so you can use CreateContainerView on the vim.VirtualMachine to get the IP addresses of each VM from your vCentre via the guest object. Although you will need to have VMWare Tools installed to gather most of the information within the guest object.
serviceInstance = SmartConnect(host=host,user=user,pwd=password,port=443)
atexit.register(Disconnect, serviceInstance)
content = serviceInstance.RetrieveContent()
vm_view = content.viewManager.CreateContainerView(content.rootFolder,[vim.VirtualMachine],True)
# Loop through the vms and print the ipAddress
for vm in vm_view.view:
print(vm.guest.ipAddress)
If you are trying to do a more advanced approach I would recommend following the getvnicinfo.py example provided on the vmware github page. This actually goes through a more detailed view getting the information for each VM. Although this doesn't seem to provide the IP Address.
To view the available vlans for a host follow the below example.
hosts = content.viewManager.CreateContainerView(content.rootFolder,[vim.HostSystem],True)
for host in hosts.view:
for network in host.network:
switch = network.config.distributedVirtualSwitch
for portgroup in switch.portgroup:
print(portgroup.name) # This will print the vlan names
I am running my own DNS name server which I have developed in python. I have a registered domain name say "abc.in". The name servers of the domain are set to my computer's IP address (given by ISP). Now whenever anyone access the domain name I am getting the visitor's ISP's IP address. I want to get the visitor's IP address. Actually I want to make a small CDN like project, also I am not able to find any good source of information. Is it possible to get the visitor's IP address, I am developing it in Python ?
I had read in CloudFlare's blog that they get the visitor's geographic information (IP address) from the initial DNS lookups.
You can use socket function in python. Like following.
>>> socket.getaddrinfo
What you're trying is simply not possible. You'll always get the connection from the resolver, not the final client.
We are using a service that require us to provide an IP in V4 format. Our application which resides on GAE reports (using python's os.environ["REMOTE_ADDR"]) for some users the IP in V6 format. Is there away to convert the IP from V6 to V4 on GAE?
Does GAE support the 6to4 transition mechanism?
Thanks,
Eden
Update:
While there is no way to convert IPv6 to IPv4 there is away to limit the access to the application to only those with IPv4. Which is an acceptable solution in my case.
See: GAE IPv6 hosting
6to4 is a deprecated method to provide IPv6 to networks that only have an IPv4 uplink. I don't think it is relevant to your question.
The very short answer: The whole world is slowly starting to enable IPv6, and Google is one of the companies that is actively working on IPv6 support. You will have to deal with IPv6 support.
A bit longer answer: IPv6 is a different protocol than IPv4. You cannot 'convert' IPv6 addresses to IPv4 addresses. IPv4 addresses and IPv6 addresses are unrelated. If your application cannot deal with IPv6 then your best bet is probably to overwrite os.environ["REMOTE_ADDR"] with a 'fake' IPv4 address when you detect an IPv6 address.
If you choose something that is never supposed to show up on the internet like 192.0.2.0 then you can later easily see which entries are caused by an IPv6 client. You won't be able to identify the client anymore though, as the 128 bits in an IPv6 address can never be put into a fake IPv4 address. You really should adjust your application to deal properly with IPv6 if IP addresses are important to you...
conn=httlib.HTTPConnection(self.proxy)
Self.proxy has destination ip and port.
I want to do multiple connection from multiple IP addresses to destination
How to specify the source IP while connect request.Please help me out.
Thanks in Advance.
I assume that you have multiple network connections on the same computer (i.e. a wired and wireless connection) and you want to make sure that your connect goes over a specific interface.
In general you cannot do this. How your traffic is sent to a specific ip address, and therefore what source ip address it shows, is determined by your operating system's routing tables. As you haven't specified what operating system this I can't go into more detail.
You may be able to do this using some of the more advanced routing configuration, but that's an operating system level problem and can't be done through Python.
I got the solution but not 100%
Requirement: Has to send request from 10 Ip address to one destination.
Achieved the same through the following API
class httplib.HTTPConnection(host[, port[, strict[, timeout[, source_address]]]])
here, we can mention the last parameter source IP
Like, httlib.HTTPConnection(dest_ip, dest_port, src_ip)
For Example:httlib.HTTPConnection("198.168.1.5",8080,"198.168.1.1")
created the connection under for loop for 10 unique src ip addresses.
Output: Connected to destination with 10 different port number with same IP address. I don't know why it happens like this.
Problem solved. Thanks for all.