Skip to content Skip to sidebar Skip to footer

Get Local Hostname From Ip Adress I.e. 192.168.1.x Python 3 On Windows 10

currently using:- import socket hostip='192.168.1.62' getip=socket.getaddrinfo(hostip,port=22) returns info but does not include Hostname. seems to be a local DNS problem from

Solution 1:

Hostname is only maintained by windows or netbios, so from a command prompt it is virtually impossible to find. So I switched to searching for the ip address by referencing the Mac address. The best solution so far is to use nmap and parse the results. My code for ip addresses up to 192.268.1.99 is this

mac='0a:0b:0c:0d'arpin=os.popen('nmap -sP -n 192.168.1.0/24',"r").read()
arl=arpin.split("\n")
fmac=[arl.index(i) for i in arl if mac in i]
fip=arl[fmac[0]-2][-12:]

fip gets the ip address of the device.

Post a Comment for "Get Local Hostname From Ip Adress I.e. 192.168.1.x Python 3 On Windows 10"