forked from p15670423/monkey
Fixed PR comments (ip casting, typos)
This commit is contained in:
parent
d35634b729
commit
4f0606d6fb
|
@ -140,27 +140,33 @@ class SingleIpRange(NetworkRange):
|
||||||
Checks if we could translate domain name entered into IP address
|
Checks if we could translate domain name entered into IP address
|
||||||
:return: True if dns found domain name and false otherwise
|
:return: True if dns found domain name and false otherwise
|
||||||
"""
|
"""
|
||||||
return hasattr(self, "_ip_address") and self._ip_address
|
return self._ip_address
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def string_to_host(string):
|
def string_to_host(string):
|
||||||
"""
|
"""
|
||||||
Converts the string that user entered in "Scan IP/subnet list" to dict of domain name and ip
|
Converts the string that user entered in "Scan IP/subnet list" to a tuple of domain name and ip
|
||||||
:param string: String that was entered in "Scan IP/subnet list"
|
:param string: String that was entered in "Scan IP/subnet list"
|
||||||
:return: A tuple in format (IP, domain_name). Eg. (192.168.55.1, www.google.com)
|
:return: A tuple in format (IP, domain_name). Eg. (192.168.55.1, www.google.com)
|
||||||
"""
|
"""
|
||||||
# The most common use case is to enter ip/range into "Scan IP/subnet list"
|
# The most common use case is to enter ip/range into "Scan IP/subnet list"
|
||||||
domain_name = ''
|
domain_name = ''
|
||||||
ip = string
|
|
||||||
|
|
||||||
# If a string was entered instead of IP we presume that it was domain name and translate it
|
# Make sure to have unicode string
|
||||||
if re.search('[a-zA-Z]', string):
|
user_input = string.decode('utf-8', 'ignore')
|
||||||
|
|
||||||
|
# Try casting user's input as IP
|
||||||
|
try:
|
||||||
|
ip = ipaddress.ip_address(user_input).exploded
|
||||||
|
except ValueError:
|
||||||
|
# Exception means that it's a domain name
|
||||||
try:
|
try:
|
||||||
ip = socket.gethostbyname(string)
|
ip = socket.gethostbyname(string)
|
||||||
domain_name = string
|
domain_name = string
|
||||||
except socket.error:
|
except socket.error:
|
||||||
LOG.error(
|
LOG.error("Your specified host: {} is not found as a domain name and"
|
||||||
"You'r specified host: {} is not found as a domain name and it's not an IP address".format(string))
|
" it's not an IP address".format(string))
|
||||||
return None, string
|
return None, string
|
||||||
|
# If a string was entered instead of IP we presume that it was domain name and translate it
|
||||||
return ip, domain_name
|
return ip, domain_name
|
||||||
|
|
||||||
|
|
|
@ -63,7 +63,7 @@ class NodeService:
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_node_label(node):
|
def get_node_label(node):
|
||||||
domain_name = node["domain_name"]
|
domain_name = ""
|
||||||
if node["domain_name"]:
|
if node["domain_name"]:
|
||||||
domain_name = " ("+node["domain_name"]+")"
|
domain_name = " ("+node["domain_name"]+")"
|
||||||
return node["os"]["version"] + " : " + node["ip_addresses"][0] + domain_name
|
return node["os"]["version"] + " : " + node["ip_addresses"][0] + domain_name
|
||||||
|
|
Loading…
Reference in New Issue