Created
November 29, 2022 12:24
-
-
Save BOAScripts/23fd103ae4d64be68331067e05bf0247 to your computer and use it in GitHub Desktop.
[py] List local NIC/IPs - subprocess, ipconfig
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
| # IMPORT | |
| import subprocess | |
| # DEF | |
| def List_LocalIPs(): | |
| ipsList = [] #{"adapterName", "adapterIp"} | |
| result=subprocess.run('ipconfig',stdout=subprocess.PIPE,text=True).stdout.lower() | |
| for l in result.split('\n'): | |
| if 'ethernet' in l or 'wireless' in l: | |
| adapterName = l.replace(':','') | |
| if 'ipv4' in l: | |
| adapterIP = l.split(':')[1].strip() | |
| ipsList.append([adapterName,adapterIP]) | |
| print(f"NIC : {adapterName} on {adapterIP}") | |
| return ipsList | |
| # EXEC | |
| localIPs = List_LocalIPs() | |
| print(localIPs) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Print only NICs that have a default gateway