-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddress.py
More file actions
37 lines (28 loc) · 880 Bytes
/
address.py
File metadata and controls
37 lines (28 loc) · 880 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env python3
import socket
from hashing import consistent_hashing
class nodeAddress:
def __init__(self,*args):
self._address = args[0]
def __hash__(self):
return consistent_hashing(self._address)
def __cmp__(self, other):
return other.__hash__() < self.__hash__()
def __eq__(self, other):
return other.__hash__() == self.__hash__()
def __str__(self):
return "{}".format(self._address)
class networkAddress:
def get_host_address(self):
host_name = socket.gethostname()
name = host_name.split('.', 1)
if (len(name)>1):
host_name = host_name.split('.', 1)[0]
else:
host_name = self.get_ip_address(host_name)
return host_name
def get_ip_address(self, host_name):
ip_address = socket.gethostbyname(host_name)
return ip_address
def __str__(self):
return "{}".format(self.get_host_address)