Python, How to get all external ip addresses with multiple NICs

后端 未结 5 1062
闹比i
闹比i 2020-12-10 18:48

What is the most efficient way to get all of the external ip address of a machine with multiple nics, using python? I understand that an external server is neeeded (I have o

5条回答
  •  自闭症患者
    2020-12-10 19:32

    Required: WMI / PyWin32 (https://sourceforge.net/projects/pywin32/)

    Use the following snippet to get the IP of the network card(s) on Windows.

    import wmi
    c = wmi.WMI()
    
    for interface in c.Win32_NetworkAdapterConfiguration(IPEnabled=1):
        print("Description: " + interface.Description)
        print("IP: " + str(interface.IPAddress[0]))
        print("MAC: " + str(interface.IPAddress[1]))
    

    For more information on what parameters you can provide Win32_NetworkAdapterConfiguration with visit: https://msdn.microsoft.com/en-us/library/aa394217(v=vs.85).aspx

提交回复
热议问题