Hack Like a Pro: How to Find the Exact Location of Any IP Address « Null Byte :: WonderHowTo

Welcome back, my tenderfoot hackers!Have you ever wondered where thephysicallocation of an IP address is? Maybe you want to know if that proxy server you are using isactuallyout of your local legal jurisdiction. Or, maybe you have the IP address of someone you are corresponding with and want to make certain they are where they say they are. Or, maybe you are a forensic investigator tracking down a suspect who wrote a threatening email or hacked someone's company.Now you can find the location of that IP address without a subpoena or search warrant.A company calledMaxMindmaintains a database of the location of every IP address on the planet complete with GPS coordinates, area code, zip code, and country. This database is not in a typical relational database format, but rather in a flat file. MaxMind charges a $370 site license and $90/month (or $1360/year) for updates to this database. Their software has a beautiful front end that makes querying the database easy enough that even Windows or Mac users can manage.MaxMind also gives away a free developers version of this database without any software or tools to read it. Although slightly less accurate than the commercial version, the price is certainly right. All we need to find the location of the IP is a program to read this data.Two programmers, Jennifer Ennis and T. Williams, have developed a small Python script called pygeoip and released it under the GPL license that enables us to input an IP address and output this critical information. I think this tutorial is self-explanatory, but if you want to refresh your Python skills before diving in, take a look atour Python tutorials.Step 1: Fire Up Kali & Open a TerminalThe first step, of course, is to fire up our our trustyKalisystem, or in this case,any Linux distribution. Then, open a terminal.Note: Be cautious of the formatting below for commands. The formatting of this article will create big space gaps since it stretches lines out to fit the margins. This is because of long URLs that try to fit themselves on a separate line. Large spaces equals just one space, so keep that in mind. Refer to the screenshots to see how they actually look.Step 2: Download the DatabaseNow we need to download the database from MaxMind, and we can get it by typing the following.kali > wget -N -qhttp://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gzThen we need to unzip it.kali> gzip -d GeoLiteCity.dat.gzLet's now check that the database is in place by listing the directory.kali > ls -alh GeoLiteCity.datStep 3: Download & Install PygeoipNext, we need to install the Python script to read the database, pygeoip. We can download it by typing the following.kali > wgethttp://pygeoip.googlecode.com/files/pygeoip-0.1.3.zipThen, unzip it.kali > unzip pygeoip-0.1.3.zipWe next need to download some setup tools into the pygeoip directory.kali > cd /pygeoip-0.1.3kali > wgethttp://svn.python.org/projects/sandbox/trunk/setuptools/ez_setup.pykali > wgethttp://pypi.python.org/packages/2.5/s/setuptools-0.6c11-py2.5.eggLet's now move and then build and install the setup tools.kali > mv setuptools-0.6c11-py2.5.egg setuptools-0.7a1-py2.5.eggkali > python setup.py buildkali > python setup.py installWe need to move the database to the pygeoip directory so that script can access it without having to use the full path.kali > mv GeoLiteCity.dat /pygeoip-0.1.3/GeoLiteCity.datStep 4: Query the DatabaseNow that we have the database in place and the pygeoip script downloaded and installed, we can begin to query that database with pygeoip.First, we need to start a Python shell.kali > pythonThen, you will be greeted will the triple >>> indicating you are now in an interactive python shell. Let's import the module and instantiate the class.>>>import pygeoip>>>gip = pygeopip.GeoIP('GeoLiteCity.dat')Next, we are ready to begin our query. Let's see where Google is located.>>>rec = gip.record_by_addr('64.233.161.99')>>>for key.val in rec.items():... print "%s: %s" %(key,val)...Please note that it is critical to indent the "print". If not, you will throw an error.As you can see, we were able to locate Google's IP in Mountain View, CA at area code 650, postal code 94043, longitude -122.0574, and latitude 37.4192. Not bad! Now, let's try to locate the IP of cnn.com.Once again, the combination of the database and pygeoip script was able to provide us with key location information on CNN's IP address.This little tool is great for locating any IP address in the world, albeit, it is a bit clunky. Maybe someone here in the Null Byte community with good Python skills would like to write an interactive script with a nice user interface where the user can simply enter the IP and get the record information?Keep coming back, my tenderfoot hackers, as we continue to explore the tools and techniques of hacking!Want to start making money as a white hat hacker?Jump-start your hacking career with our2020 Premium Ethical Hacking Certification Training Bundlefrom the newNull Byte Shopand get over 60 hours of training from cybersecurity professionals.Buy Now (90% off) >Other worthwhile deals to check out:97% off The Ultimate 2021 White Hat Hacker Certification Bundle99% off The 2021 All-in-One Data Scientist Mega Bundle98% off The 2021 Premium Learn To Code Certification Bundle62% off MindMaster Mind Mapping Software: Perpetual LicenseCover image viaShutterstockRelatedHacker Fundamentals:The Everyman's Guide to How Network Packets Are Routed Across the WebHacker Fundamentals:A Tale of Two StandardsHow To:Use Dropbox to Track and Locate Your Stolen LaptopHow To:Trace Any IP AddressHack Like a Pro:How to Exploit and Gain Remote Access to PCs Running Windows XPHack Like a Pro:Networking Basics for the Aspiring Hacker, Part 1Instagram 101:How to Remove Your Location from Instagram PhotosHow To:Find someone's IP addressHow To:Find the Location of Any IP with PyGeo IP Locator(GUI for GeoIP/Pygeoip)Hack Like a Pro:Linux Basics for the Aspiring Hacker, Part 6 (Networking Basics)How To:Find the IP address of a websiteHow To:Understand & Use IPv4 to Navigate a NetworkHow To:Save Both a Home & Work Address on Google Maps When You Work from HomeHow To:Linux Basics for the Aspiring Hacker: Using Ship for Quick & Handy IP Address InformationHow To:Assign a Static IP Address in Windows 7Hacker Fundamentals:A Gentle Introduction to How IP Addresses WorkHow To:How Hackers Use Your IP Address to Hack Your Computer & How to Stop ItHow To:Chain Proxies to Mask Your IP Address and Remain Anonymous on the WebHow To:Make a Change-of-IP Notifier in PythonHow To:Find your external IP addressHow To:Bypass a Local Network Proxy for Free InternetHow To:Turn Your House Lights On & Off Using the InternetHow To:Code a Basic TCP/IP Client & Server Duo in PythonMastering Security, Part 2:How to Create a Home VPN Tunnel