How to find location based on IP address in Excel

samthebrand

I've got a spreadsheet of about 5000 user events associated with IPs, and I'm trying to use IP to determine location using just an Excel formula. The IPs in my log are structured as "dotted quads" (decimal notation).

I figured VLOOKUP is the way to go here, so I downloaded WEBNet77's IPV4 IpToCountry database, which seems like a comprehensive and up-to-date resource (is there a better resource out there for this purpose?). The database includes about 140K rows of IP ranges, with the sheet structured like so:

IP address lookup

Colum labels A - G are, respectively: IP FROM, IP TO, REGISTRY, ASSIGNED, CTRY, CNTRY, COUNTRY.

Notice, a problem: columns A to B represent a range of IPs, but they are in the "long format" (I didn't realize this at first). So, before using these values as a reference, I'll have to convert my dotted quads. Then, I'd like to return Country (column G) for each of the IPs in my log.

Any help here?

And if you think there's a better way to lookup IP > Country in Excel (maybe using the web ie. http://api.hostip.info/flag.php?ip=xxx.xxx.xxx.xxx), please do let me know.

Brad

You can convert your quad IP to a numeric using this function

Function GetNumericIP(quadIP As String) As Long

    Dim sections
    On Error Resume Next
    sections = Split(quadIP, ".")

    GetNumericIP = sections(3) * 256 ^ 0 + sections(2) * 256 ^ 1 + sections(1) * 256 ^ 2 + sections(0) * 256 ^ 3
End Function

And you can use MATCH/INDEX to get your location. The trick is to have your IP TO column sorted ascending. The Match function will return index of the row for the last value in the range which is less the given value.

57.182.90.111  your input
968252015      =GetNumericIP(A1)
France         =INDEX(Country,MATCH(J6,IPTO,1)+1)
  (Or alternatively) =INDEX(Country,MATCH(J6,IPFROM,1))

Notice I had to import the CSV (not just reference it externally) and I turned the columns into named ranges (Country, IPTO). For other's information, the CSV linked in the question has column names of:

  • IP FROM
  • IP TO
  • REGISTRY
  • ASSIGNED
  • CTRY
  • CNTRY
  • COUNTRY

Alternately, you can convert your dotted quad IP into its constituent parts using only formulas, though it's a bit of a hassle. Here are the first two sections (my IP was in I5)

=LEFT(I5,FIND(".",I5)-1)
=LEFT(RIGHT(I5,LEN(I5)-I10),SEARCH(".",RIGHT(I5,LEN(I5)-I10))-1)

You can see...kind of a pain. Easier: use the VBA method explained above, OR use Text to Columns (on the ribbon: Data > Data Tools > Text To Columns > Delimited > Next > Other: "." > Next > Finish). Then write a formula to convert your split dotted-quad IP to the IP format in your reference database. This formula works:

=sumproduct(J5:M5, 256^{3,2,1,0})

Remember to sub in your column range for J5:M5 above. Then run MATCH/INDEX against the new value.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to find a domain based on the IP address?

From Dev

How to find ip address in codeigniter?

From Dev

How to find IP address of domains?

From Dev

How does geolocation based on IP address work?

From Dev

How to restrict user based on ip address in openldap

From Dev

how to find the IP address of an email recipient

From Dev

How to find Google's IP address?

From Dev

How to find your private IP address on DigitalOcean?

From Dev

How to find my computer's IP Address?

From Dev

How to find valid static IP address?

From Dev

How to find IP address of ADSL modem?

From Dev

How can I find the IP address in a string

From Dev

How to find private ip address on google cloud?

From Dev

Hadoop : find the hostname or IP address based on the process id

From Dev

How to find an ip address if we have the mac address

From Dev

How to obtain latitude and longitude of a user by IP address or pinpoint location

From Dev

How to obtain user browser details, IP address and location information?

From Dev

In Excel how do I convert a location's address to a block address for privacy without redacting intersections or location names?

From Dev

How to find location of link in Excel workbook?

From Dev

How to achieve resolving of the same hostname to different IP addresses based on location

From Dev

ip2location for finding ip address of a specific location only

From Dev

How to obtain accurate latitude and longitude of user machine based on IP address

From Dev

How to plot IP address frequency distribution chart on Excel or Calc?

From Java

How can this tool find out registered domains from an IP address?

From Dev

How to find historical geolocation for an IP address, perhaps using maxmind?

From Dev

How to find the ip address of a jenkins node from the master

From Dev

How to find the client ip address from a HttpHeaders object in java?

From Dev

How can I find the IP address of connected network in windows phone?

From Dev

How to find CIDR subnet for a public Internet IP address?

Related Related

  1. 1

    How to find a domain based on the IP address?

  2. 2

    How to find ip address in codeigniter?

  3. 3

    How to find IP address of domains?

  4. 4

    How does geolocation based on IP address work?

  5. 5

    How to restrict user based on ip address in openldap

  6. 6

    how to find the IP address of an email recipient

  7. 7

    How to find Google's IP address?

  8. 8

    How to find your private IP address on DigitalOcean?

  9. 9

    How to find my computer's IP Address?

  10. 10

    How to find valid static IP address?

  11. 11

    How to find IP address of ADSL modem?

  12. 12

    How can I find the IP address in a string

  13. 13

    How to find private ip address on google cloud?

  14. 14

    Hadoop : find the hostname or IP address based on the process id

  15. 15

    How to find an ip address if we have the mac address

  16. 16

    How to obtain latitude and longitude of a user by IP address or pinpoint location

  17. 17

    How to obtain user browser details, IP address and location information?

  18. 18

    In Excel how do I convert a location's address to a block address for privacy without redacting intersections or location names?

  19. 19

    How to find location of link in Excel workbook?

  20. 20

    How to achieve resolving of the same hostname to different IP addresses based on location

  21. 21

    ip2location for finding ip address of a specific location only

  22. 22

    How to obtain accurate latitude and longitude of user machine based on IP address

  23. 23

    How to plot IP address frequency distribution chart on Excel or Calc?

  24. 24

    How can this tool find out registered domains from an IP address?

  25. 25

    How to find historical geolocation for an IP address, perhaps using maxmind?

  26. 26

    How to find the ip address of a jenkins node from the master

  27. 27

    How to find the client ip address from a HttpHeaders object in java?

  28. 28

    How can I find the IP address of connected network in windows phone?

  29. 29

    How to find CIDR subnet for a public Internet IP address?

HotTag

Archive