From 690b69b2f45d63262e86ef3016fb0c8fadd98296 Mon Sep 17 00:00:00 2001 From: ndyer Date: Tue, 20 Dec 2022 12:36:54 -0500 Subject: [PATCH] added file to help get interface information --- pypong/networking/__init__.py | 0 pypong/networking/host.py | 36 +++++++++++++++++++++++++++++++++++ requirements.txt | 3 ++- 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 pypong/networking/__init__.py create mode 100644 pypong/networking/host.py diff --git a/pypong/networking/__init__.py b/pypong/networking/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/pypong/networking/host.py b/pypong/networking/host.py new file mode 100644 index 0000000..3ba7be4 --- /dev/null +++ b/pypong/networking/host.py @@ -0,0 +1,36 @@ +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() diff --git a/requirements.txt b/requirements.txt index 1581372..fd1045c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ -pygame~=2.1.2 \ No newline at end of file +pygame~=2.1.2 +psutil~=5.9.4 \ No newline at end of file