Forum Discussion
IP address mapping
- 9 years ago
Hi reno1
You can do it with the following steps below.
You need to create a function with the following code below with the name of fn_GetIPAddress
let Source = (#"IP Address" as text) => let Source = Json.Document(Web.Contents("http://freegeoip.net/json/" & #"IP Address")), #"Converted to Table" = Record.ToTable(Source), #"Transposed Table" = Table.Transpose(#"Converted to Table"), #"Promoted Headers" = Table.PromoteHeaders(#"Transposed Table") in #"Promoted Headers" in SourceThe function will return the output into a table.
Then what you do is where your data is in the Query Editor you click on Invoke Custom Function, then put in the required fields as shown below.
NOTE: Make sure to select your column above that has got the IP Addresses
Then once you click Ok you will see the table as shown below.
Click on the Expand Table button, leave all the defaults and click Ok.
You should then get the details for each IP Address.
NOTE: There are more columns but I snipped them off.
Please let me know if this works or you get stuck.
Hi reno1,
From my understanding of IP Addresses you first need to do a lookup to an IP Address database or IP Address file in which you can then find out where the IP Address is allocated from. And then get the output from the IP Address database or file and use that to put it into a map.
I would assume you would need to get the IP Address database or file and then due to the structure of the file, you would need to do some process to find out where the IP Address sits within the range of allocated IP Addresses. Once that is done it would be able to link the location of the IP Address and use that in a map?
It would be a bit of a process to get this working.
GilbertQ thanks for the response.
I have found an IP address database and successfully imported it into power BI. What I am unsure about now is how to find where each IP address sits within the range of IP addresses in the IP database. The IP addresses I have are in the format '8.8.8.8', and the corresponding row in the IP database is '8.8.8.0/16'. Do you have any idea how to do this in Power BI, or where I can go to for information?
- dkay84_PowerBI9 years agoMicrosoft Employee
I assume the subnet doesn't change the location of the ip range, correct?
Can you share the IP locations database? Or provide some sample data that we can play with?
- GilbertQ9 years agoSuper User
Hi reno1, yes that would be the next challenge to convert it into the range of IP Addresses.
Another thought is if it is possible to pass the IP Address to a Online Lookup Service which would then return the location of the IP Address. And then store the value?
dkay84_PowerBI, you are correct in that the Subnet does not affect the IP Address due to the IP Addresses being in ranges.
- reno19 years agoFrequent Visitor
dkay84_PowerBI, I got the database from 'http://dev.maxmind.com/geoip/geoip2/geolite2/'. I downloaded the csv files and added them to my SQL Server database. I then imported the tables into Power BI.
GilbertQ, I also had this thought before posting the question. I was planning to use the site 'http://freegeoip.net/' to get the location. For example, when I go to the URL:
http://freegeoip.net/json/8.8.8.8
it returns the JSON:
{"ip":"8.8.8.8","country_code":"US","country_name":"United States","region_code":"CA","region_name":"California","city":"Mountain View","zip_code":"94035","time_zone":"America/Los_Angeles","latitude":37.386,"longitude":-122.0838,"metro_code":807}This provides all the information I need, though I cannot figure out how to do this automatically for each IP address in Power BI, leading me to ask this question.
- GilbertQ9 years agoSuper User
Hi reno1
You can do it with the following steps below.
You need to create a function with the following code below with the name of fn_GetIPAddress
let Source = (#"IP Address" as text) => let Source = Json.Document(Web.Contents("http://freegeoip.net/json/" & #"IP Address")), #"Converted to Table" = Record.ToTable(Source), #"Transposed Table" = Table.Transpose(#"Converted to Table"), #"Promoted Headers" = Table.PromoteHeaders(#"Transposed Table") in #"Promoted Headers" in SourceThe function will return the output into a table.
Then what you do is where your data is in the Query Editor you click on Invoke Custom Function, then put in the required fields as shown below.
NOTE: Make sure to select your column above that has got the IP Addresses
Then once you click Ok you will see the table as shown below.
Click on the Expand Table button, leave all the defaults and click Ok.
You should then get the details for each IP Address.
NOTE: There are more columns but I snipped them off.
Please let me know if this works or you get stuck.