How to get Network Interface Card names in Python?

后端 未结 9 1796
灰色年华
灰色年华 2020-12-06 09:36

I am totally new to python programming so please be patient with me.

Is there anyway to get the names of the NIC cards in the machine etc. eth0, lo? If so how do you

9条回答
  •  伪装坚强ぢ
    2020-12-06 10:11

    There is a python package get-nic which gives NIC status, up\down, ip addr, mac addr etc

    
    pip install get-nic
    
    from get_nic import getnic
    
    getnic.interfaces()
    
    Output: ["eth0", "wlo1"]
    
    interfaces = getnic.interfaces()
    getnic.ipaddr(interfaces)
    
    Output: 
    {'lo': {'state': 'UNKNOWN', 'inet4': '127.0.0.1/8', 'inet6': '::1/128'}, 'enp3s0': {'state': 'DOWN', 'HWaddr': 'a4:5d:36:c2:34:3e'}, 'wlo1': {'state': 'UP', 'HWaddr': '48:d2:24:7f:63:10', 'inet4': '10.16.1.34/24', 'inet6': 'fe80::ab4a:95f7:26bd:82dd/64'}}
    

    Refer GitHub page for more information: https://github.com/tech-novic/get-nic-details

提交回复
热议问题