Browse Source

Convert to python3 and add ipv6 support

Yann Weber 1 year ago
parent
commit
e90ce4fced
7 changed files with 326 additions and 36 deletions
  1. 23
    0
      geo6.py
  2. 1
    1
      main.py
  3. 3
    1
      mapData/SOURCES
  4. 257
    0
      mapData/countries.csv
  5. 17
    9
      tracer.py
  6. 9
    9
      vtracemap.py
  7. 16
    16
      vtracert.py

+ 23
- 0
geo6.py View File

1
+import csv
2
+
3
+import GeoIP
4
+
5
+gi6 = GeoIP.open("/usr/share/GeoIP/GeoIPv6.dat",GeoIP.GEOIP_STANDARD)
6
+
7
+countries = {}
8
+with open('mapData/countries.csv') as csvfile:
9
+	reader = csv.DictReader(csvfile, delimiter=',', quotechar='"')
10
+	rows = [r for r in reader]
11
+	countries = {row['Alpha-2 code']:{'lon':row['Longitude (average)'],'lat': row['Latitude (average)']}
12
+		for row in rows}
13
+	countries.update({row['Alpha-3 code']:{'lon':row['Longitude (average)'],'lat': row['Latitude (average)']}
14
+		for row in rows})
15
+
16
+def ip62coord(ipv6):
17
+	res = gi6.country_code_by_addr_v6(ipv6)
18
+	if res is not None:
19
+		if res in countries:
20
+			coord = countries[res]
21
+			return float(coord['lon']), float(coord['lat'])
22
+	return None
23
+

+ 1
- 1
main.py View File

1
-#!/usr/bin/python -O
1
+#!/usr/bin/env python3
2
 # -*- coding: utf-8 -*-#
2
 # -*- coding: utf-8 -*-#
3
 
3
 
4
 # Copyright 2015 Weber Yann
4
 # Copyright 2015 Weber Yann

+ 3
- 1
mapData/SOURCES View File

1
-Data extracted from files from http://www.mappinghacks.com/data/ Licenced under Creative Commons Attribution-Share Alike License 3.0
1
+Data extracted from files from http://www.mappinghacks.com/data/ Licenced under Creative Commons Attribution-Share Alike License 3.0
2
+
3
+Countries.csv : https://gist.github.com/tadast/8827699

+ 257
- 0
mapData/countries.csv View File

1
+"Country","Alpha-2 code","Alpha-3 code","Numeric code","Latitude (average)","Longitude (average)"
2
+"Afghanistan","AF","AFG","4","33","65"
3
+"Albania","AL","ALB","8","41","20"
4
+"Algeria","DZ","DZA","12","28","3"
5
+"American Samoa","AS","ASM","16","-14.3333","-170"
6
+"Andorra","AD","AND","20","42.5","1.6"
7
+"Angola","AO","AGO","24","-12.5","18.5"
8
+"Anguilla","AI","AIA","660","18.25","-63.1667"
9
+"Antarctica","AQ","ATA","10","-90","0"
10
+"Antigua and Barbuda","AG","ATG","28","17.05","-61.8"
11
+"Argentina","AR","ARG","32","-34","-64"
12
+"Armenia","AM","ARM","51","40","45"
13
+"Aruba","AW","ABW","533","12.5","-69.9667"
14
+"Australia","AU","AUS","36","-27","133"
15
+"Austria","AT","AUT","40","47.3333","13.3333"
16
+"Azerbaijan","AZ","AZE","31","40.5","47.5"
17
+"Bahamas","BS","BHS","44","24.25","-76"
18
+"Bahrain","BH","BHR","48","26","50.55"
19
+"Bangladesh","BD","BGD","50","24","90"
20
+"Barbados","BB","BRB","52","13.1667","-59.5333"
21
+"Belarus","BY","BLR","112","53","28"
22
+"Belgium","BE","BEL","56","50.8333","4"
23
+"Belize","BZ","BLZ","84","17.25","-88.75"
24
+"Benin","BJ","BEN","204","9.5","2.25"
25
+"Bermuda","BM","BMU","60","32.3333","-64.75"
26
+"Bhutan","BT","BTN","64","27.5","90.5"
27
+"Bolivia, Plurinational State of","BO","BOL","68","-17","-65"
28
+"Bolivia","BO","BOL","68","-17","-65"
29
+"Bosnia and Herzegovina","BA","BIH","70","44","18"
30
+"Botswana","BW","BWA","72","-22","24"
31
+"Bouvet Island","BV","BVT","74","-54.4333","3.4"
32
+"Brazil","BR","BRA","76","-10","-55"
33
+"British Indian Ocean Territory","IO","IOT","86","-6","71.5"
34
+"Brunei Darussalam","BN","BRN","96","4.5","114.6667"
35
+"Brunei","BN","BRN","96","4.5","114.6667"
36
+"Bulgaria","BG","BGR","100","43","25"
37
+"Burkina Faso","BF","BFA","854","13","-2"
38
+"Burundi","BI","BDI","108","-3.5","30"
39
+"Cambodia","KH","KHM","116","13","105"
40
+"Cameroon","CM","CMR","120","6","12"
41
+"Canada","CA","CAN","124","60","-95"
42
+"Cape Verde","CV","CPV","132","16","-24"
43
+"Cayman Islands","KY","CYM","136","19.5","-80.5"
44
+"Central African Republic","CF","CAF","140","7","21"
45
+"Chad","TD","TCD","148","15","19"
46
+"Chile","CL","CHL","152","-30","-71"
47
+"China","CN","CHN","156","35","105"
48
+"Christmas Island","CX","CXR","162","-10.5","105.6667"
49
+"Cocos (Keeling) Islands","CC","CCK","166","-12.5","96.8333"
50
+"Colombia","CO","COL","170","4","-72"
51
+"Comoros","KM","COM","174","-12.1667","44.25"
52
+"Congo","CG","COG","178","-1","15"
53
+"Congo, the Democratic Republic of the","CD","COD","180","0","25"
54
+"Cook Islands","CK","COK","184","-21.2333","-159.7667"
55
+"Costa Rica","CR","CRI","188","10","-84"
56
+"Côte d'Ivoire","CI","CIV","384","8","-5"
57
+"Ivory Coast","CI","CIV","384","8","-5"
58
+"Croatia","HR","HRV","191","45.1667","15.5"
59
+"Cuba","CU","CUB","192","21.5","-80"
60
+"Cyprus","CY","CYP","196","35","33"
61
+"Czech Republic","CZ","CZE","203","49.75","15.5"
62
+"Denmark","DK","DNK","208","56","10"
63
+"Djibouti","DJ","DJI","262","11.5","43"
64
+"Dominica","DM","DMA","212","15.4167","-61.3333"
65
+"Dominican Republic","DO","DOM","214","19","-70.6667"
66
+"Ecuador","EC","ECU","218","-2","-77.5"
67
+"Egypt","EG","EGY","818","27","30"
68
+"El Salvador","SV","SLV","222","13.8333","-88.9167"
69
+"Equatorial Guinea","GQ","GNQ","226","2","10"
70
+"Eritrea","ER","ERI","232","15","39"
71
+"Estonia","EE","EST","233","59","26"
72
+"Ethiopia","ET","ETH","231","8","38"
73
+"Falkland Islands (Malvinas)","FK","FLK","238","-51.75","-59"
74
+"Faroe Islands","FO","FRO","234","62","-7"
75
+"Fiji","FJ","FJI","242","-18","175"
76
+"Finland","FI","FIN","246","64","26"
77
+"France","FR","FRA","250","46","2"
78
+"French Guiana","GF","GUF","254","4","-53"
79
+"French Polynesia","PF","PYF","258","-15","-140"
80
+"French Southern Territories","TF","ATF","260","-43","67"
81
+"Gabon","GA","GAB","266","-1","11.75"
82
+"Gambia","GM","GMB","270","13.4667","-16.5667"
83
+"Georgia","GE","GEO","268","42","43.5"
84
+"Germany","DE","DEU","276","51","9"
85
+"Ghana","GH","GHA","288","8","-2"
86
+"Gibraltar","GI","GIB","292","36.1833","-5.3667"
87
+"Greece","GR","GRC","300","39","22"
88
+"Greenland","GL","GRL","304","72","-40"
89
+"Grenada","GD","GRD","308","12.1167","-61.6667"
90
+"Guadeloupe","GP","GLP","312","16.25","-61.5833"
91
+"Guam","GU","GUM","316","13.4667","144.7833"
92
+"Guatemala","GT","GTM","320","15.5","-90.25"
93
+"Guernsey","GG","GGY","831","49.5","-2.56"
94
+"Guinea","GN","GIN","324","11","-10"
95
+"Guinea-Bissau","GW","GNB","624","12","-15"
96
+"Guyana","GY","GUY","328","5","-59"
97
+"Haiti","HT","HTI","332","19","-72.4167"
98
+"Heard Island and McDonald Islands","HM","HMD","334","-53.1","72.5167"
99
+"Holy See (Vatican City State)","VA","VAT","336","41.9","12.45"
100
+"Honduras","HN","HND","340","15","-86.5"
101
+"Hong Kong","HK","HKG","344","22.25","114.1667"
102
+"Hungary","HU","HUN","348","47","20"
103
+"Iceland","IS","ISL","352","65","-18"
104
+"India","IN","IND","356","20","77"
105
+"Indonesia","ID","IDN","360","-5","120"
106
+"Iran, Islamic Republic of","IR","IRN","364","32","53"
107
+"Iraq","IQ","IRQ","368","33","44"
108
+"Ireland","IE","IRL","372","53","-8"
109
+"Isle of Man","IM","IMN","833","54.23","-4.55"
110
+"Israel","IL","ISR","376","31.5","34.75"
111
+"Italy","IT","ITA","380","42.8333","12.8333"
112
+"Jamaica","JM","JAM","388","18.25","-77.5"
113
+"Japan","JP","JPN","392","36","138"
114
+"Jersey","JE","JEY","832","49.21","-2.13"
115
+"Jordan","JO","JOR","400","31","36"
116
+"Kazakhstan","KZ","KAZ","398","48","68"
117
+"Kenya","KE","KEN","404","1","38"
118
+"Kiribati","KI","KIR","296","1.4167","173"
119
+"Korea, Democratic People's Republic of","KP","PRK","408","40","127"
120
+"Korea, Republic of","KR","KOR","410","37","127.5"
121
+"South Korea","KR","KOR","410","37","127.5"
122
+"Kuwait","KW","KWT","414","29.3375","47.6581"
123
+"Kyrgyzstan","KG","KGZ","417","41","75"
124
+"Lao People's Democratic Republic","LA","LAO","418","18","105"
125
+"Latvia","LV","LVA","428","57","25"
126
+"Lebanon","LB","LBN","422","33.8333","35.8333"
127
+"Lesotho","LS","LSO","426","-29.5","28.5"
128
+"Liberia","LR","LBR","430","6.5","-9.5"
129
+"Libyan Arab Jamahiriya","LY","LBY","434","25","17"
130
+"Libya","LY","LBY","434","25","17"
131
+"Liechtenstein","LI","LIE","438","47.1667","9.5333"
132
+"Lithuania","LT","LTU","440","56","24"
133
+"Luxembourg","LU","LUX","442","49.75","6.1667"
134
+"Macao","MO","MAC","446","22.1667","113.55"
135
+"Macedonia, the former Yugoslav Republic of","MK","MKD","807","41.8333","22"
136
+"Madagascar","MG","MDG","450","-20","47"
137
+"Malawi","MW","MWI","454","-13.5","34"
138
+"Malaysia","MY","MYS","458","2.5","112.5"
139
+"Maldives","MV","MDV","462","3.25","73"
140
+"Mali","ML","MLI","466","17","-4"
141
+"Malta","MT","MLT","470","35.8333","14.5833"
142
+"Marshall Islands","MH","MHL","584","9","168"
143
+"Martinique","MQ","MTQ","474","14.6667","-61"
144
+"Mauritania","MR","MRT","478","20","-12"
145
+"Mauritius","MU","MUS","480","-20.2833","57.55"
146
+"Mayotte","YT","MYT","175","-12.8333","45.1667"
147
+"Mexico","MX","MEX","484","23","-102"
148
+"Micronesia, Federated States of","FM","FSM","583","6.9167","158.25"
149
+"Moldova, Republic of","MD","MDA","498","47","29"
150
+"Monaco","MC","MCO","492","43.7333","7.4"
151
+"Mongolia","MN","MNG","496","46","105"
152
+"Montenegro","ME","MNE","499","42","19"
153
+"Montserrat","MS","MSR","500","16.75","-62.2"
154
+"Morocco","MA","MAR","504","32","-5"
155
+"Mozambique","MZ","MOZ","508","-18.25","35"
156
+"Myanmar","MM","MMR","104","22","98"
157
+"Burma","MM","MMR","104","22","98"
158
+"Namibia","NA","NAM","516","-22","17"
159
+"Nauru","NR","NRU","520","-0.5333","166.9167"
160
+"Nepal","NP","NPL","524","28","84"
161
+"Netherlands","NL","NLD","528","52.5","5.75"
162
+"Netherlands Antilles","AN","ANT","530","12.25","-68.75"
163
+"New Caledonia","NC","NCL","540","-21.5","165.5"
164
+"New Zealand","NZ","NZL","554","-41","174"
165
+"Nicaragua","NI","NIC","558","13","-85"
166
+"Niger","NE","NER","562","16","8"
167
+"Nigeria","NG","NGA","566","10","8"
168
+"Niue","NU","NIU","570","-19.0333","-169.8667"
169
+"Norfolk Island","NF","NFK","574","-29.0333","167.95"
170
+"Northern Mariana Islands","MP","MNP","580","15.2","145.75"
171
+"Norway","NO","NOR","578","62","10"
172
+"Oman","OM","OMN","512","21","57"
173
+"Pakistan, "PK","PAK","586","30","70"
174
+"Palau","PW","PLW","585","7.5","134.5"
175
+"Palestinian Territory, Occupied","PS","PSE","275","32","35.25"
176
+"Panama","PA","PAN","591","9","-80"
177
+"Papua New Guinea","PG","PNG","598","-6","147"
178
+"Paraguay","PY","PRY","600","-23","-58"
179
+"Peru","PE","PER","604","-10","-76"
180
+"Philippines","PH","PHL","608","13","122"
181
+"Pitcairn","PN","PCN","612","-24.7","-127.4"
182
+"Poland","PL","POL","616","52","20"
183
+"Portugal","PT","PRT","620","39.5","-8"
184
+"Puerto Rico","PR","PRI","630","18.25","-66.5"
185
+"Qatar","QA","QAT","634","25.5","51.25"
186
+"Réunion","RE","REU","638","-21.1","55.6"
187
+"Romania","RO","ROU","642","46","25"
188
+"Russian Federation","RU","RUS","643","60","100"
189
+"Russia","RU","RUS","643","60","100"
190
+"Rwanda","RW","RWA","646","-2","30"
191
+"Saint Helena, Ascension and Tristan da Cunha","SH","SHN","654","-15.9333","-5.7"
192
+"Saint Kitts and Nevis","KN","KNA","659","17.3333","-62.75"
193
+"Saint Lucia","LC","LCA","662","13.8833","-61.1333"
194
+"Saint Pierre and Miquelon","PM","SPM","666","46.8333","-56.3333"
195
+"Saint Vincent and the Grenadines","VC","VCT","670","13.25","-61.2"
196
+"Saint Vincent & the Grenadines","VC","VCT","670","13.25","-61.2"
197
+"St. Vincent and the Grenadines","VC","VCT","670","13.25","-61.2"
198
+"Samoa","WS","WSM","882","-13.5833","-172.3333"
199
+"San Marino","SM","SMR","674","43.7667","12.4167"
200
+"Sao Tome and Principe","ST","STP","678","1","7"
201
+"Saudi Arabia","SA","SAU","682","25","45"
202
+"Senegal","SN","SEN","686","14","-14"
203
+"Serbia","RS","SRB","688","44","21"
204
+"Seychelles","SC","SYC","690","-4.5833","55.6667"
205
+"Sierra Leone","SL","SLE","694","8.5","-11.5"
206
+"Singapore","SG","SGP","702","1.3667","103.8"
207
+"Slovakia","SK","SVK","703","48.6667","19.5"
208
+"Slovenia","SI","SVN","705","46","15"
209
+"Solomon Islands","SB","SLB","90","-8","159"
210
+"Somalia","SO","SOM","706","10","49"
211
+"South Africa","ZA","ZAF","710","-29","24"
212
+"South Georgia and the South Sandwich Islands","GS","SGS","239","-54.5","-37"
213
+"South Sudan","SS","SSD","728","8","30"
214
+"Spain","ES","ESP","724","40","-4"
215
+"Sri Lanka","LK","LKA","144","7","81"
216
+"Sudan","SD","SDN","736","15","30"
217
+"Suriname","SR","SUR","740","4","-56"
218
+"Svalbard and Jan Mayen","SJ","SJM","744","78","20"
219
+"Swaziland","SZ","SWZ","748","-26.5","31.5"
220
+"Sweden","SE","SWE","752","62","15"
221
+"Switzerland","CH","CHE","756","47","8"
222
+"Syrian Arab Republic","SY","SYR","760","35","38"
223
+"Taiwan, Province of China","TW","TWN","158","23.5","121"
224
+"Taiwan","TW","TWN","158","23.5","121"
225
+"Tajikistan","TJ","TJK","762","39","71"
226
+"Tanzania, United Republic of","TZ","TZA","834","-6","35"
227
+"Thailand","TH","THA","764","15","100"
228
+"Timor-Leste","TL","TLS","626","-8.55","125.5167"
229
+"Togo","TG","TGO","768","8","1.1667"
230
+"Tokelau","TK","TKL","772","-9","-172"
231
+"Tonga","TO","TON","776","-20","-175"
232
+"Trinidad and Tobago","TT","TTO","780","11","-61"
233
+"Tunisia","TN","TUN","788","34","9"
234
+"Turkey","TR","TUR","792","39","35"
235
+"Turkmenistan","TM","TKM","795","40","60"
236
+"Turks and Caicos Islands","TC","TCA","796","21.75","-71.5833"
237
+"Tuvalu","TV","TUV","798","-8","178"
238
+"Uganda","UG","UGA","800","1","32"
239
+"Ukraine","UA","UKR","804","49","32"
240
+"United Arab Emirates","AE","ARE","784","24","54"
241
+"United Kingdom","GB","GBR","826","54","-2"
242
+"United States","US","USA","840","38","-97"
243
+"United States Minor Outlying Islands","UM","UMI","581","19.2833","166.6"
244
+"Uruguay","UY","URY","858","-33","-56"
245
+"Uzbekistan","UZ","UZB","860","41","64"
246
+"Vanuatu","VU","VUT","548","-16","167"
247
+"Venezuela, Bolivarian Republic of","VE","VEN","862","8","-66"
248
+"Venezuela","VE","VEN","862","8","-66"
249
+"Viet Nam","VN","VNM","704","16","106"
250
+"Vietnam","VN","VNM","704","16","106"
251
+"Virgin Islands, British","VG","VGB","92","18.5","-64.5"
252
+"Virgin Islands, U.S.","VI","VIR","850","18.3333","-64.8333"
253
+"Wallis and Futuna","WF","WLF","876","-13.3","-176.2"
254
+"Western Sahara","EH","ESH","732","24.5","-13"
255
+"Yemen","YE","YEM","887","15","48"
256
+"Zambia","ZM","ZMB","894","-15","30"
257
+"Zimbabwe","ZW","ZWE","716","-20","30"

+ 17
- 9
tracer.py View File

26
 
26
 
27
 import vtracemap
27
 import vtracemap
28
 import vtracert
28
 import vtracert
29
+import geo6
29
 
30
 
30
 class Tracer:
31
 class Tracer:
31
 	
32
 	
92
 		p = Popen(['traceroute', dest_name], stdout=PIPE)
93
 		p = Popen(['traceroute', dest_name], stdout=PIPE)
93
 		
94
 		
94
 		#First line give us destination ip
95
 		#First line give us destination ip
95
-		line = p.stdout.readline()
96
+		line = p.stdout.readline().decode('utf-8')
96
 		
97
 		
97
 		ml = self.regetip.match(line)
98
 		ml = self.regetip.match(line)
98
 		if ml != None:
99
 		if ml != None:
99
 			dest_ip = ml.group(1)
100
 			dest_ip = ml.group(1)
100
 			
101
 			
101
-			(dlon,dlat) = self.ip2coord(dest_ip)
102
-			(x,y) = self.vtr.trmap.latlon2ortho(dlon, dlat)
102
+			if ':' in dest_ip:
103
+				coord = geo6.ip62coord(dest_ip)
104
+			else:
105
+				coord = self.ip2coord(dest_ip)
106
+			if coord is not None:
107
+				dlon, dlat = coord
108
+				(x,y) = self.vtr.trmap.latlon2ortho(dlon, dlat)
103
 
109
 
104
-			pygame.gfxdraw.circle(self.vtr.surf['trace'],x,y,3,self.vtr.col['trace_end'])
110
+				pygame.gfxdraw.circle(self.vtr.surf['trace'],x,y,3,self.vtr.col['trace_end'])
105
 			
111
 			
106
 		else:
112
 		else:
107
 			dest_ip = None
113
 			dest_ip = None
111
 		
117
 		
112
 		#Reading traceroute output
118
 		#Reading traceroute output
113
 		while True:
119
 		while True:
114
-			line = p.stdout.readline()
120
+			line = p.stdout.readline().decode('utf-8')
115
 			if not line:
121
 			if not line:
116
 				break
122
 				break
117
 			
123
 			
118
-			print line
124
+			print(line)
119
 			
125
 			
120
 			#Getting hop number
126
 			#Getting hop number
121
 			ml = self.regHop.match(line)
127
 			ml = self.regHop.match(line)
229
 	# @param (lon,lat) Hop coordinates
235
 	# @param (lon,lat) Hop coordinates
230
 	# @param selected A boolean
236
 	# @param selected A boolean
231
 	# @return The coordinates of the hop on the screen as (x,y)
237
 	# @return The coordinates of the hop on the screen as (x,y)
232
-	def drawNext(self, (lon, lat), selected = False, last = False):
238
+	def drawNext(self, pos, selected = False, last = False):
239
+		lon,lat=pos
233
 		
240
 		
234
 		if not selected :
241
 		if not selected :
235
 			#If not selected draw a circle
242
 			#If not selected draw a circle
334
 			rng = range(len(self.ips))
341
 			rng = range(len(self.ips))
335
 		else:
342
 		else:
336
 			rng = range(stopAt)
343
 			rng = range(stopAt)
344
+		rng=list(rng)
337
 		rng.reverse()
345
 		rng.reverse()
338
 		for i in rng:
346
 		for i in rng:
339
 			strStatus = self.hops[i]+' '+self.hosts[i]
347
 			strStatus = self.hops[i]+' '+self.hosts[i]
356
 	# @param (x,y) The on screen coordinates
364
 	# @param (x,y) The on screen coordinates
357
 	# @param maxDist The maximum distance bellow wich a hop is selected
365
 	# @param maxDist The maximum distance bellow wich a hop is selected
358
 	# @return A list of hop index
366
 	# @return A list of hop index
359
-	def searchHopByCoord(self, (x,y), maxDist = 10):
360
-		
367
+	def searchHopByCoord(self, coord, maxDist = 10):
368
+		x,y=coord
361
 		maxDist = maxDist **2
369
 		maxDist = maxDist **2
362
 		
370
 		
363
 		curRes = []
371
 		curRes = []

+ 9
- 9
vtracemap.py View File

32
 # @param (lon, lat) Coordinates
32
 # @param (lon, lat) Coordinates
33
 # @param arg ( (lonmin,lonmax,latmin,latmax), scaleW, scaleH, xlim)
33
 # @param arg ( (lonmin,lonmax,latmin,latmax), scaleW, scaleH, xlim)
34
 # @return (x,y) or None
34
 # @return (x,y) or None
35
-def draw__ProcessFun((lon, lat), arg ):
36
-	
35
+def draw__ProcessFun(coord, arg ):
36
+	lon,lat = coord
37
 	( (lonmin,lonmax,latmin,latmax), scaleW, scaleH, xlim) = arg
37
 	( (lonmin,lonmax,latmin,latmax), scaleW, scaleH, xlim) = arg
38
 	
38
 	
39
 	if lonmin > lonmax:
39
 	if lonmin > lonmax:
122
 		self.vtr.blitScreen('map')
122
 		self.vtr.blitScreen('map')
123
 		
123
 		
124
 		btime = time.time()#timer
124
 		btime = time.time()#timer
125
-		print "Map draw spent ",(btime-atime)*1000,"miliseconds"
125
+		print("Map draw spent ",(btime-atime)*1000,"miliseconds")
126
 		
126
 		
127
 		pass
127
 		pass
128
 	
128
 	
181
 			pygame.display.flip()
181
 			pygame.display.flip()
182
 			
182
 			
183
 		btime = time.time()
183
 		btime = time.time()
184
-		print "Map OLDdraw spent ",(btime-atime)*1000,"miliseconds"
184
+		print("Map OLDdraw spent ",(btime-atime)*1000,"miliseconds")
185
 	
185
 	
186
 	## Generate limits from lon and lat to convert coordinates
186
 	## Generate limits from lon and lat to convert coordinates
187
 	# @param lonmin Longitude mini
187
 	# @param lonmin Longitude mini
216
 	## Zoom on the map
216
 	## Zoom on the map
217
 	# @param (cx,cy) Where to center the zoom
217
 	# @param (cx,cy) Where to center the zoom
218
 	# @param zoom If True zoom if False zoom out and can be a direction str 'up' 'down' 'left' 'right' to move on the map
218
 	# @param zoom If True zoom if False zoom out and can be a direction str 'up' 'down' 'left' 'right' to move on the map
219
-	def zoom(self,(cx,cy), zoom = True):
220
-		
219
+	def zoom(self,coord, zoom = True):
220
+		cx,cy=coord
221
 		width = self.vtr.surf['map'].get_width()
221
 		width = self.vtr.surf['map'].get_width()
222
 		height = self.vtr.surf['map'].get_height()
222
 		height = self.vtr.surf['map'].get_height()
223
 		
223
 		
303
 	
303
 	
304
 		res = []
304
 		res = []
305
 		
305
 		
306
-		fd = file(coordFile,"r")
306
+		fd = open(coordFile,"r")
307
 
307
 
308
 		buff = ''
308
 		buff = ''
309
 		lat = 0.0
309
 		lat = 0.0
366
 		buff = [ struct.pack('f', lon)+struct.pack('f', lat) for (lon, lat) in lonlat ]
366
 		buff = [ struct.pack('f', lon)+struct.pack('f', lat) for (lon, lat) in lonlat ]
367
 		buff = b''.join(buff)
367
 		buff = b''.join(buff)
368
 		
368
 		
369
-		print len(buff)
369
+		print(len(buff))
370
 		
370
 		
371
 		fd.write(buff)
371
 		fd.write(buff)
372
 		fd.close()
372
 		fd.close()
444
 		lon -= 360
444
 		lon -= 360
445
 		
445
 		
446
 		return (lon,lat)
446
 		return (lon,lat)
447
-	
447
+	

+ 16
- 16
vtracert.py View File

22
 "|                Controls summary                         |",
22
 "|                Controls summary                         |",
23
 "+----------------------+----------------------------------+",
23
 "+----------------------+----------------------------------+",
24
 "+----------------------+----------------------------------+",
24
 "+----------------------+----------------------------------+",
25
-"| ^h, ?                |  display this help               |",
25
+"| ?                    |  display this help               |",
26
 "+----------------------+----------------------------------+",
26
 "+----------------------+----------------------------------+",
27
 "| esc, ^q              |  exit the programm or this help  |",
27
 "| esc, ^q              |  exit the programm or this help  |",
28
 "+----------------------+----------------------------------+",
28
 "+----------------------+----------------------------------+",
182
 	## Return the unicode representation of the combiation of ctrl+a letter key
182
 	## Return the unicode representation of the combiation of ctrl+a letter key
183
 	@classmethod
183
 	@classmethod
184
 	def ctrlUnicode(classo, c):
184
 	def ctrlUnicode(classo, c):
185
-		return unicode(chr(ord(c.lower())-ord('a')+1))
185
+		return chr(ord(c.lower())-ord('a')+1)
186
 		pass
186
 		pass
187
 	
187
 	
188
 	##Display an help on the screen and wait for an KEYDOWN or QUIT event
188
 	##Display an help on the screen and wait for an KEYDOWN or QUIT event
196
 			"",
196
 			"",
197
 			"Controls summary :",
197
 			"Controls summary :",
198
 			"",
198
 			"",
199
-			"^h, ?                : display this help",
199
+			"?                    : display this help",
200
 			"esc, ^q              : exit the programm or this help",
200
 			"esc, ^q              : exit the programm or this help",
201
 			"",
201
 			"",
202
 			"[a-zA-Z0-9\.]        : Host input",
202
 			"[a-zA-Z0-9\.]        : Host input",
370
 		
370
 		
371
 		c2u = Vtracert.ctrlUnicode
371
 		c2u = Vtracert.ctrlUnicode
372
 		
372
 		
373
-		allowedChar = range(ord('a'),ord('z')+1) 
374
-		allowedChar += range(ord('A'),ord('Z')+1)
375
-		allowedChar += range(ord('0'),ord('9')+1)
376
-		allowedChar += [ord('.'),ord('\b'),ord('\r'),ord('\n')]
373
+		allowedChar = list(range(ord('a'),ord('z')+1))
374
+		allowedChar += list(range(ord('A'),ord('Z')+1))
375
+		allowedChar += list(range(ord('0'),ord('9')+1))
376
+		allowedChar += [ord('.'),ord('\b'),ord('\r'),ord(':'),ord('\n')]
377
 		
377
 		
378
 		allowedChar = [ chr(cc) for cc in allowedChar ]
378
 		allowedChar = [ chr(cc) for cc in allowedChar ]
379
 		ctrlChar = [	c2u('q'), #^q
379
 		ctrlChar = [	c2u('q'), #^q
380
-						c2u('h'), #^h
381
 						c2u('n'), #^n
380
 						c2u('n'), #^n
382
 						c2u('c'), #^n
381
 						c2u('c'), #^n
383
 						'?',
382
 						'?',
386
 		
385
 		
387
 		#print evt
386
 		#print evt
388
 		#print self.ctrl
387
 		#print self.ctrl
388
+		cc = evt.unicode
389
 		
389
 		
390
 		if ccode in [273,274,275,276]: #Arrow keys
390
 		if ccode in [273,274,275,276]: #Arrow keys
391
 			if ccode == 273:
391
 			if ccode == 273:
411
 			cc = evt.unicode
411
 			cc = evt.unicode
412
 			if cc == u'\x1b' or cc == c2u('q'): #quit (esc or ^q)
412
 			if cc == u'\x1b' or cc == c2u('q'): #quit (esc or ^q)
413
 				pygame.event.post(pygame.event.Event(pygame.QUIT))
413
 				pygame.event.post(pygame.event.Event(pygame.QUIT))
414
-			elif cc == c2u('h') or cc == '?': #help ^h ? ^?
415
-				print "Help !!!!!!!!"
414
+			elif cc == '?': #help ^?
415
+				print("Help !!!!!!!!")
416
 				self.help()
416
 				self.help()
417
 				self.flip()
417
 				self.flip()
418
 			elif cc == c2u('c'):
418
 			elif cc == c2u('c'):
435
 				if len(self.inputText) > 0:
435
 				if len(self.inputText) > 0:
436
 					self.inputText = self.inputText[:-1]
436
 					self.inputText = self.inputText[:-1]
437
 			elif cc == '\r' or cc == '\n':
437
 			elif cc == '\r' or cc == '\n':
438
-				print "OK, tracerouting %s ..."%self.inputText
438
+				print("OK, tracerouting %s ..."%self.inputText)
439
 				dest = self.inputText
439
 				dest = self.inputText
440
 				self.inputText = ""
440
 				self.inputText = ""
441
 				
441
 				
470
 		elif evt.button == 1:
470
 		elif evt.button == 1:
471
 			#Trying to select hops
471
 			#Trying to select hops
472
 			if self.tracer.select(evt.pos):
472
 			if self.tracer.select(evt.pos):
473
-				print 'Selected : \n',self.tracer.selectedIp()
473
+				print('Selected : \n',self.tracer.selectedIp())
474
 			self.tracer.drawTrace(0)
474
 			self.tracer.drawTrace(0)
475
 			
475
 			
476
 		elif evt.button == 2:
476
 		elif evt.button == 2:
479
 				inputTxt += clipTxt
479
 				inputTxt += clipTxt
480
 				self.drawPrompt()
480
 				self.drawPrompt()
481
 		else:
481
 		else:
482
-			print "\n\n"
482
+			print("\n\n")
483
 			types = pygame.scrap.get_types()
483
 			types = pygame.scrap.get_types()
484
 			for t in types:
484
 			for t in types:
485
-				print t,pygame.scrap.get(t)
485
+				print(t,pygame.scrap.get(t))
486
 		
486
 		
487
 		pass
487
 		pass
488
 	
488
 	
495
 		self.flip()
495
 		self.flip()
496
 		
496
 		
497
 		#Display small onetime help text
497
 		#Display small onetime help text
498
-		htext = self.font['status'].render("Type ^h or ? for help.",1, self.col['status'])
498
+		htext = self.font['status'].render("Type ? for help.",1, self.col['status'])
499
 		self.surf['screen'].blit(htext, (5, self.font['status'].get_linesize()+2))
499
 		self.surf['screen'].blit(htext, (5, self.font['status'].get_linesize()+2))
500
 		pygame.display.flip()
500
 		pygame.display.flip()
501
 		
501
 		
516
 				
516
 				
517
 				self.drawPrompt();
517
 				self.drawPrompt();
518
 				self.flip()
518
 				self.flip()
519
-	
519
+	

Loading…
Cancel
Save