从IP地址获取本地主机名,即Windows 10上的192.168.1.x python 3 [英] 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)
返回信息,但不包含主机名. 从其他讨论来看,这似乎是一个本地DNS问题. 本地路由器会找到所有主机名.
returns info but does not include Hostname. seems to be a local DNS problem from other discussions. The local router finds all hostnames.
推荐答案
主机名仅由Windows或netbios维护,因此在命令提示符下几乎找不到.因此,我切换为通过引用Mac地址来搜索IP地址. 到目前为止,最好的解决方案是使用nmap并解析结果. 我的ip地址最多为192.268.1.99的代码是
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获取设备的IP地址.
fip gets the ip address of the device.
这篇关于从IP地址获取本地主机名,即Windows 10上的192.168.1.x python 3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!