Last active
March 19, 2019 11:55
-
-
Save light-bringer/24b48e1304b82b2922a881dd0042b7f2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import requests | |
| def get_city(ipaddr): | |
| url = "https://www.ipinfo.io/" + str(ipaddr) | |
| response = requests.get(url=url).json() | |
| return response['city'] | |
| lines = open('log.txt').readlines() | |
| cities = {} | |
| ipaddresses = [] | |
| for line in lines: | |
| ipaddresses.append(line.split()[3].split(':')[0]) | |
| ipaddresses = list(set(ipaddresses)) | |
| for ipaddr in ipaddresses: | |
| city = get_city(ipaddr) | |
| if (city in cities): | |
| cities[city] += 1 | |
| else: | |
| cities[city] = 1 | |
| print cities | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {u'Ulsoor': 1, u'Hyderabad': 2, u'Chennai': 1, u'Ludhiana': 1, u'Lucknow': 1, u'New Delhi': 2, u'Mallesvaram': 1, u'Delhi': 2, u'Yelachenahalli': 1, u'Sulthan Bathery': 1, u'Kachiguda': 4, u'Raichur': 1, u'Bengaluru': 35, u'Sampla': 1, u'Bangalore': 1, u'Ahmedabad': 1, u'Mangalore': 2} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment