Last active
March 13, 2018 03:40
-
-
Save MaHu6/de38fa001d804e472f355827e171aa97 to your computer and use it in GitHub Desktop.
python script for getNetNameAndIp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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