philhagen / ip2geo Goto Github PK
View Code? Open in Web Editor NEWScript to perform bulk local GeoIP lookups (ASN and geo) for IP addresses
Script to perform bulk local GeoIP lookups (ASN and geo) for IP addresses
I cannot figure out why, but so IP got this error. Could you give a error message instead ?
$ echo 185.222.209.222 | python3 ip2geo.py -f "%ip,%cn,%asname"
Traceback (most recent call last):
File "ip2geo.py", line 172, in
output_string = output_re.sub(lambda x: output_record[format_map[x.group()][0]], args.format)
File "ip2geo.py", line 172, in
output_string = output_re.sub(lambda x: output_record[format_map[x.group()][0]], args.format)
KeyError: 'ipaddress'
Dear Phil Hagen,
Good morning. How are you?
The ip2geo has worked for almost all format options except the %ci:
[root@ol72 ip2geo]# echo 190.93.240.233 | ./ip2geo.py -f %ci
Traceback (most recent call last):
File "./ip2geo.py", line 160, in
output_string = output_re.sub(lambda x: str(ipdata[format_map[x.group()][0]]), args.format)
File "./ip2geo.py", line 160, in
output_string = output_re.sub(lambda x: str(ipdata[format_map[x.group()][0]]), args.format)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 7: ordinal not in range(128)
Unfortunately, in a very bad luck case, the city would be San José and the last letter can be a problem to convert to ASCII text. Therefore, I have modified your program to use Unicode and instead of reading:
output_string = output_re.sub(lambda x: str(ipdata[format_map[x.group()][0]]), args.format)
Now we read the following line:
output_string = output_re.sub(lambda x: (u''.join(ipdata[format_map[x.group()][0]]).encode('utf-8')), args.format)
My recommendation is to avoid using str(), if possible.
I am sorry for touching in your program. Anyway, it is a good work. Congratulations.
I hope you have a nice day and thank you for the attention.
Alexandre Borges.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.