python获取本地ip地址的方法
2015-01-13 13:57
716 查看
''' The Method for getting Local Host IP address under the Linux. '''
# Uses the Linux SIOCGIFADDR ioctl to find the IP address associated with a network interface,
# given the name of that interface, e.g. “eth0”.
# The address is returned as a string containing a dotted quad.
def getLocalHost(if_name='eth0'):
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
return socket.inet_ntoa(fcntl.ioctl(
s.fileno(),
0x8915, # SIOCGIFADDR
struct.pack('256s', if_name[:15])
)[20:24])
# Uses the Linux SIOCGIFADDR ioctl to find the IP address associated with a network interface,
# given the name of that interface, e.g. “eth0”.
# The address is returned as a string containing a dotted quad.
def getLocalHost(if_name='eth0'):
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
return socket.inet_ntoa(fcntl.ioctl(
s.fileno(),
0x8915, # SIOCGIFADDR
struct.pack('256s', if_name[:15])
)[20:24])
相关文章推荐
- python获取本地ip地址的方法
- python取本地mac地址,ip地址,非ipconfig方法
- python在Windows8下获取本机ip地址的方法
- Linux下编程获取本地IP地址的常见方法
- Python实现获取本地及远程图片大小的方法示例
- Python2.7基于淘宝接口获取IP地址所在地理位置的方法【测试可用】
- python获取本地的IP地址及mac地址
- python简单获取本机计算机名和IP地址的方法
- python获取本地IP地址发送邮件
- 通过Python在windows和linux中获取当前网络IP地址的一些方法
- Python简单获取网卡名称及其IP地址的方法【基于psutil模块】
- windows下,Python中获取本地磁盘卷标的方法
- python获取本地计算机名字的方法
- python批量生成本地ip地址的方法
- shell 脚本获取本地ip地址方法
- live555学习心得二(获取本地IP地址方法1)
- python在Windows8下获取本机ip地址的方法
- python获取本机mac地址和ip地址的方法
- python获取本机mac地址和ip地址的方法
- Android开发实现在Wifi下获取本地IP地址的方法