37 lines
1.2 KiB
Python
37 lines
1.2 KiB
Python
|
import psutil
|
||
|
|
||
|
|
||
|
class InterfaceInfo:
|
||
|
"""
|
||
|
Class used for storing interface information to make it easier to use
|
||
|
"""
|
||
|
def __init__(self, interface_name, address, subnet_mask):
|
||
|
self.interface_name = interface_name
|
||
|
self.address = address
|
||
|
self.subnet_mask = subnet_mask
|
||
|
|
||
|
def __str__(self):
|
||
|
return '(Interface:{0}, Address:{1}, Subnet Mask:{2})'.format(self.interface_name,
|
||
|
self.address, self.subnet_mask)
|
||
|
|
||
|
def __repr__(self):
|
||
|
return '(Interface:{0}, Address:{1}, Subnet Mask:{2})'.format(self.interface_name,
|
||
|
self.address, self.subnet_mask)
|
||
|
|
||
|
|
||
|
def main():
|
||
|
raw_interface_data = psutil.net_if_addrs()
|
||
|
interface_data = []
|
||
|
|
||
|
# Extract needed information from psutil and put it into a InterfaceInfo object
|
||
|
for interface in raw_interface_data:
|
||
|
address = (raw_interface_data.get(interface)[0]).address
|
||
|
subnet_mask = (raw_interface_data.get(interface)[0]).netmask
|
||
|
interface_data.append(InterfaceInfo(interface, address, subnet_mask))
|
||
|
|
||
|
print(interface_data)
|
||
|
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
main()
|