Skip to content

Instantly share code, notes, and snippets.

@MaHu6
Last active March 13, 2018 03:40
Show Gist options
  • Select an option

  • Save MaHu6/de38fa001d804e472f355827e171aa97 to your computer and use it in GitHub Desktop.

Select an option

Save MaHu6/de38fa001d804e472f355827e171aa97 to your computer and use it in GitHub Desktop.
python script for getNetNameAndIp
# run pip3 install psutil
import psutil
#获取网卡名称和其ip地址,不包括回环
def get_netcard():
netcard_info = []
info = psutil.net_if_addrs()
for k,v in info.items():
for item in v:
if item[0] == 2 and not item[1]=='127.0.0.1':
netcard_info.append((k,item[1]))
return netcard_info
if __name__ == '__main__':
print(get_netcard())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment