added file to help get interface information
This commit is contained in:
parent
23b62c4c13
commit
690b69b2f4
0
pypong/networking/__init__.py
Normal file
0
pypong/networking/__init__.py
Normal file
36
pypong/networking/host.py
Normal file
36
pypong/networking/host.py
Normal 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()
|
@ -1 +1,2 @@
|
||||
pygame~=2.1.2
|
||||
psutil~=5.9.4
|
Loading…
Reference in New Issue
Block a user