使用Python获取本机所有IP地址
#!/usr/bin/env python
# coding=gbk
# This program is optimized for Python 2.7.
import socket
localIP = socket.gethostbyname(socket.gethostname())
print "Local IP:"
print " %s" % localIP
ipList = socket.gethostbyname_ex(socket.gethostname())
for i in ipList:
# 过滤空序列、主机名和localIP(localIP不是业务地址发情况)
if i and (not isinstance(i, str)) and (i != localIP):
print "External IP:"
for ip in i:
print " %s" % ip