PBA telem - Add fallback to ip & hostname collection

This commit is contained in:
itay 2019-07-07 12:07:04 +03:00
parent a9ec2a39bc
commit 6aca7d6f29
1 changed files with 11 additions and 2 deletions

View File

@ -16,8 +16,7 @@ class PostBreachTelem(BaseTelem):
super(PostBreachTelem, self).__init__()
self.pba = pba
self.result = result
self.hostname = socket.gethostname()
self.ip = socket.gethostbyname(self.hostname)
self.hostname, self.ip = PostBreachTelem._get_hostname_and_ip()
telem_category = 'post_breach'
@ -29,3 +28,13 @@ class PostBreachTelem(BaseTelem):
'hostname': self.hostname,
'ip': self.ip
}
@staticmethod
def _get_hostname_and_ip():
try:
hostname = socket.gethostname()
ip = socket.gethostbyname(hostname)
except socket.error:
hostname = "Unknown"
ip = "Unknown"
return hostname, ip