mshd.net
当前位置:首页 >> python获取本机外网ip >>

python获取本机外网ip

>>> import socket >>> hostname = socket.gethostname() >>> print hostname LuciferYang.local >>> ip = socket.gethostbyname(hostname) >>> print ip 10.101.8.171 >>> ipList = socket.gethostbyname_ex(hostname) >>> print ipList ('luci...

import socket localIP = socket.gethostbyname(socket.gethostname())#得到本地ip print "local ip:%s "%localIP

第一种: 复制代码代码如下: import socket import fcntl import struct def get_ip_address(ifname): s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) return socket.inet_ntoa(fcntl.ioctl( s.fileno(), 0x8915, # SIOCGIFADDR struct....

import socketdef get_ip(): s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) try: # doesn't even have to be reachable s.connect(('10.255.255.255', 0)) IP = s.getsockname()[0] except: IP = '127.0.0.1' finally: s.close() retur...

import socket ip = socket.gethostbyname("www.google.com")

以前是有这样的工具,它会通过常用协议去刺探设备类型。比如windows的版本,计算机名等。现在不知道还有没有这样的工具,搜索一下看。 哦。这个应该相当容易了。因为相机是专业设备。所以通常会有一个控制协议。因为是专业的,所以这个socket应...

def get_local_ipaddr(): results = [] for i in netifaces.interfaces(): info = netifaces.ifaddresses(i) if netifaces.AF_INET not in info: continue results.append(info[netifaces.AF_INET][0]['addr']) return results if __name__ == '...

#!/usr/bin/pythonimport fcntl, socket, structdef getHwAddr(ifname): s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) info = fcntl.ioctl(s.fileno(), 0x8927, struct.pack('256s', ifname[:15])) return ':'.join(['%02x' % ord(cha...

这样可以获取到本机所有网卡的IP地址: IPs = socket.gethostbyname_ex(socket.gethostname())[-1] 如果想获取正在上网所使用的本机IP,通过route命令可以得到: [a for a in os.popen('route print').readlines() if ' 0.0.0.0 ' in a][0].spli...

import sys, sockettry:ipLines = open('ip.txt').readlines()results = []for ip in ipLines:result = socket.gethostbyaddr(ip.replace('\n',''))results.append(result[0])print "Primary hostname:"print " " + result[0]print "\nAddresses...

网站首页 | 网站地图
All rights reserved Powered by www.mshd.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com