Advertisement
steve-shambles-2109

IP Tracer

Mar 28th, 2020
1,303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.58 KB | None | 0 0
  1. """Code snippets vol-47-snippet-231
  2.   IP Tracer
  3.  
  4. Download all snippets so far:
  5. https://wp.me/Pa5TU8-1yg
  6.  
  7. Blog: stevepython.wordpress.com
  8.  
  9. requirements:pip3 install requests
  10.  
  11. origin:
  12. https://gist.github.com/angeloped/127395a702e66c563f70e992957218e3
  13. """
  14. import webbrowser as wb
  15. import requests
  16.  
  17. def _input(form):
  18.     try:
  19.         return raw_input(form)
  20.     except:
  21.         return input(form)
  22.  
  23.  
  24. tracing = _input('Enter IP (defaults to your own IP if none): ')
  25.  
  26. req = requests.get('http://ip-api.com/json/{0}'.format(tracing)).json()
  27.  
  28. if req['status'] == 'success':
  29.     result = '''
  30.    IP:      {0}
  31.    Address: {1}, {2} ({3})
  32.    Region:  {4}
  33.    Zip:     {5}
  34.    T-zone:  {6}
  35.    Coords:
  36.        LAT:  {7}
  37.        LON:  {8}
  38.    ISP:     {9}
  39.    Org:     {10}
  40.    '''
  41.     result = result.format(req['query'], req['city'], req['country'],
  42.                            req['countryCode'], req['region'], req['zip'],
  43.                            req['timezone'], req['lat'], req['lon'],
  44.                            req['isp'], req['org'])
  45.  
  46.     print(result)
  47.  
  48.     mapping = '''[1] Google Map
  49. [2] Ip Tracker
  50. Which web service you'd like
  51. to geolocate IP (select none to exit): '''
  52.  
  53.     choice = _input(mapping)
  54.  
  55.     if choice == '1':
  56.         wb.open('https://www.google.com/maps/@{0},{1},13z'.
  57.                                 format(req['lat'], req['lon']))
  58.     elif choice == '2':
  59.         wb.open('https://www.ip-tracker.org/locator/ip-lookup.php?ip={0}'.
  60.                                 format(req['query']))
  61. else:
  62.     print('We FAILED attempting to track subject..')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement