How to get Network Interface Card names in Python?

后端 未结 9 1831
灰色年华
灰色年华 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:13

    To add to what @Kristian Evensen's mentions, here is what I used for a problem i was having. If you are looking to just get a list of the interfaces, use:

    interface_list = netifaces.interfaces()
    

    If you are wanting a specific interface, but don't know what the number at the end is (ie: eth0), use:

    interface_list = netifaces.interfaces()
    interface = filter(lambda x: 'eth' in x,interface_list)
    

提交回复
热议问题