updated client anserver for week02 easy
This commit is contained in:
17
week02/easy/check_interface.py
Normal file
17
week02/easy/check_interface.py
Normal file
@ -0,0 +1,17 @@
|
||||
import netifaces
|
||||
|
||||
|
||||
def print_ethernet_interfaces():
|
||||
"""Prints all Ethernet interfaces and their IP addresses."""
|
||||
|
||||
interfaces = netifaces.interfaces()
|
||||
for interface in interfaces:
|
||||
addresses = netifaces.ifaddresses(interface)
|
||||
if netifaces.AF_INET in addresses:
|
||||
for addr in addresses[netifaces.AF_INET]:
|
||||
ip_address = addr["addr"]
|
||||
print(f"Interface: {interface}, IP Address: {ip_address}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print_ethernet_interfaces()
|
Reference in New Issue
Block a user