Skip to content

Commit cb37b7e

Browse files
committed
fix(ippool): fix geo ip bug
1 parent c8c7642 commit cb37b7e

3 files changed

Lines changed: 12 additions & 10 deletions

File tree

smartdns/ippool.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,13 @@ def ip2long(ip):
1919
return int(hexn, 16)
2020

2121

22-
def long2ip(n):
22+
def long2ip(num):
2323
"convert long int to dotted quad string"
24-
d = 256 * 256 * 256
25-
q = []
26-
while d > 0:
27-
m, n = divmod(n, d)
28-
q.append(str(m))
29-
d = d/256
30-
return '.'.join(q)
24+
iplist = []
25+
for n in range(4):
26+
num,mod = divmod(num,256)
27+
iplist.insert(0,str(mod))
28+
return '.'.join(iplist)
3129

3230

3331
class IPPool(object):
@@ -103,7 +101,7 @@ def LoadRecord(self):
103101
continue
104102
p = None
105103
# p = re.match(ur"(.*),(.*),(.*),(.*)", router)
106-
p = str(router.encode('utf-8')).strip().split(',')
104+
p = router.strip().split(',')
107105
if p is None:
108106
logger.warning(
109107
"maybe record file format error: %s" % self.recordfile)
@@ -133,6 +131,7 @@ def LoadRecord(self):
133131
elif match[3] not in self.locmapip[fqdn][match[0]][match[1]][match[2]]:
134132
self.locmapip[fqdn][match[0]][match[1]][match[2]][match[3]] = \
135133
[self.record[fqdn][router], weight]
134+
print(self.locmapip)
136135
f.close()
137136
# logger.warning(self.locmapip)
138137

@@ -203,6 +202,8 @@ def FindIP(self, ip, name):
203202
if not re.search(r'[^0-9.]', tmp_ip) and self.monitor_mapping.check(name, tmp_ip)]
204203
logger.info("userip:[%s] domain:[%s] section:[%s-%s] location:[%s,%s,%s,%s] ip_list:%s" % (
205204
ip, name, long2ip(ipstart), long2ip(ipend), country, province, city, sp, ip_list))
205+
print(self.iphash[i])
206+
print(name, ipnum, ip, long2ip(ipstart), long2ip(ipend),country, province, city, sp, ip_list)
206207
if not ip_list or len(ip_list) == 0:
207208
# maybe something wrong
208209
tmp_ip_list = [

templates/a.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ horizon.parkone.cn:
1313
中国,,,: 1.1.1.9 3.3.3.9
1414
美国,,,: 1.1.1.10 3.3.3.10
1515
马来西亚,,,: 1.1.1.11 3.3.3.11
16-
土耳其,,,: 1.1.1.12 3.3.3.12
16+
内网,,,: 1.1.1.12 3.3.3.12

templates/ip.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135152,3 +135152,4 @@
135152135152
3758096128,3758096383,澳大利亚,,,
135153135153
3758096384,3774873599,IANA,,,
135154135154
3774873600,4026531839,IANA保留地址,,,用于多点传送
135155+
3232237056,3232237311,内网,,,

0 commit comments

Comments
 (0)