4242 os .mkdir (default_path )
4343 copyfile (os .path .dirname (os .path .realpath (__file__ )) + os .sep + "data" + os .sep + "IP2LOCATION-LITE-DB1.IPV6.BIN" , default_path + "IP2LOCATION-LITE-DB1.IPV6.BIN" )
4444 except PermissionError as e :
45- sys .exit ("Root permission is required. Please rerun it as 'sudo ip2trace' ." )
45+ sys .exit ("Root permission is required. Please rerun it as 'sudo ip2tracepy' in Linux, or obtain administrator permission in Windows ." )
4646
4747if sys .platform .startswith ('win32' ):
48- timer = time .clock
48+ # timer = time.clock
49+ if sys .version_info > (3 ,2 ):
50+ timer = time .perf_counter
51+ else :
52+ timer = time .clock
4953else :
5054 timer = time .time
55+ # timer = time.time
5156
5257def calculate_checksum (packet ):
5358 countTo = (len (packet ) // 2 ) * 2
@@ -94,8 +99,14 @@ def to_ip(hostname):
9499
95100def ip_to_domain_name (hostname ):
96101 if is_valid_ip (hostname ):
97- return socket .gethostbyaddr (hostname )
98- return hostname
102+ # return socket.gethostbyaddr(hostname)
103+ try :
104+ return socket .gethostbyaddr (hostname )
105+ except socket .herror :
106+ # return hostname
107+ return None
108+ # return hostname
109+ return None
99110
100111
101112def create_parser ():
@@ -113,8 +124,8 @@ def create_parser():
113124
114125def print_usage ():
115126 print (
116- "Usage: ip2trace -p [IP ADDRESS/HOSTNAME] -d [IP2LOCATION BIN DATA PATH] [OPTIONS]\n "
117- " or: ip2trace [IP ADDRESS/HOSTNAME] -d [IP2LOCATION BIN DATA PATH] [OPTIONS]\n \n "
127+ "Usage: ip2tracepy -p [IP ADDRESS/HOSTNAME] -d [IP2LOCATION BIN DATA PATH] [OPTIONS]\n "
128+ " or: ip2tracepy [IP ADDRESS/HOSTNAME] -d [IP2LOCATION BIN DATA PATH] [OPTIONS]\n \n "
118129" -p, --ip\n "
119130" Specify an IP address or hostname.\n "
120131" The -p/--ip can be omitted if the IP address or hostname is defined in the first parameter.\n "
@@ -140,7 +151,7 @@ def print_usage():
140151
141152def print_version ():
142153 print (
143- "IP2Location Geolocation Traceroute (ip2trace) Version 2.1.7 \n "
154+ "IP2Location Geolocation Traceroute (ip2trace) Version 3.0.0 \n "
144155"Copyright (c) 2021 IP2Location.com [MIT License]\n "
145156"https://www.ip2location.com/free/traceroute-application\n " )
146157
@@ -204,7 +215,7 @@ def __init__(self, destination_server, database, max_hops, output, all):
204215 if (os .path .isfile (default_path + "IP2LOCATION-LITE-DB1.IPV6.BIN" ) != False ):
205216 self .obj = IP2Location .IP2Location (default_path + "IP2LOCATION-LITE-DB1.IPV6.BIN" )
206217 else :
207- print ("Missing IP2Location BIN database. Please enter ‘ ip2trace -h’ for more information." )
218+ print ("Missing IP2Location BIN database. Please enter ' ip2trace -h' for more information." )
208219 sys .exit ()
209220
210221 # check the output list
@@ -215,12 +226,14 @@ def __init__(self, destination_server, database, max_hops, output, all):
215226 sys .exit ()
216227
217228 def print_start (self ):
218- print ("IP2Location Geolocation Traceroute (ip2trace) Version 2.1.7 \n "
229+ print ("IP2Location Geolocation Traceroute (ip2trace) Version 3.0.0 \n "
219230"Copyright (c) 2021 IP2Location.com [MIT License]\n "
220231"https://www.ip2location.com/free/traceroute-application\n \n " )
221- # "Traceroute to", self.destination_domain_name, "(", self.destination_ip, ")\n\n")
222- # "Traceroute to", self.destination_domain_name[0], "(", self.destination_ip, ")\n\n")
223- print ("Traceroute to" , self .destination_domain_name [0 ], "(" , self .destination_ip , ")\n \n " , end = "" )
232+ # print("Traceroute to", self.destination_domain_name[0], "(", self.destination_ip, ")\n\n", end="")
233+ if self .destination_domain_name is not None :
234+ print ("Traceroute to" , self .destination_domain_name [0 ], "(" , self .destination_ip , ")\n \n " , end = "" )
235+ else :
236+ print ("Traceroute to" , self .destination_ip , "\n \n " , end = "" )
224237
225238 def print_unknownhost (self ):
226239 print ("traceroute: unknown host {}" .format (self .destination_server ))
@@ -481,4 +494,4 @@ def main():
481494 # sys.exit()
482495 traceroute (destination_server , database , max_hops , output , all )
483496 else :
484- print ("Missing parameters. Please enter 'ip2trace -h' for more information." )
497+ print ("Missing parameters. Please enter 'ip2trace -h' for more information." )
0 commit comments