added file to help get interface information

This commit is contained in:
Nicholas Dyer 2022-12-20 12:36:54 -05:00
parent 23b62c4c13
commit 690b69b2f4
No known key found for this signature in database
GPG Key ID: E4E6388793FA2105
3 changed files with 38 additions and 1 deletions

View File

36
pypong/networking/host.py Normal file
View File

@ -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()

View File

@ -1 +1,2 @@
pygame~=2.1.2
pygame~=2.1.2
psutil~=5.9.4