Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use python to get Network Card and ip

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "how to use python to obtain network card and ip", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn "how to use python to obtain network card and ip"!

Def get_interface_ip (ifname): sckt = socket.socket (socket.AF_INET, socket.SOCK_DGRAM) return socket.inet_ntoa (fcntl.ioctl (sckt.fileno (), 0x8915, # SIOCGIFADDR struct.pack ('256s') Ifname [: 15]) [20:24]) def _ get_interface_list (): "Provides a list of available network interfaces as a list of tuples (name) Ip) "" max_iface = 32 # Maximum number of interfaces (Aribtrary) bytes = max_iface * 32 is_32bit = (8 * struct.calcsize ("P")) = 32 # Set Architecture struct_size = 32 if is_32bit else 40 try: s = socket.socket (socket.AF_INET, socket.SOCK_DGRAM) names = array.array ('baked,'\ 0' * bytes) outbytes = struct.unpack ('iL' Fcntl.ioctl (s.fileno (), 0x8912, # SIOCGIFCONF struct.pack ('iL', bytes, names.buffer_info () [0])) [0] namestr = names.tostring () return [(namestr [i0x8912 + 32] .split ('\ 0mm, 1) [0]) Socket.inet_ntoa (namestre [I + 20 struct_size I + 24]))\ for i in range (0, outbytes, struct_size)] except IOError: raise NetworkError ('Unable to call ioctl with SIOCGIFCONF') so far I believe you have a deeper understanding of "how to use python to obtain network card and ip". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report