ip2asn¶
ip2asn(ip)
Description¶
Get asn
of ip
This functions uses IP address data powered by IPinfo and released under Creative Commons Attribution-ShareAlike 4.0 International License. You are required to attribute IPinfo to use their free datasets. The attribution requirements can be met by giving their service credit as your data source. Simply place a link to IPinfo on the website, application, or social media account that uses their data.
Usage¶
Call or Deploy ip2asn
?
Call ip2asn
directly
The easiest way to use bigfunctions
ip2asn
function is deployed in 39 public datasets for all of the 39 BigQuery regions.- It can be called by anyone. Just copy / paste examples below in your BigQuery console. It just works!
- (You need to use the dataset in the same region as your datasets otherwise you may have a function not found error)
Public BigFunctions Datasets
Region | Dataset |
---|---|
eu |
bigfunctions.eu |
us |
bigfunctions.us |
europe-west1 |
bigfunctions.europe_west1 |
asia-east1 |
bigfunctions.asia_east1 |
... | ... |
Deploy ip2asn
in your project
Why deploy?
- You may prefer to deploy
ip2asn
in your own project to build and manage your own catalog of functions. - This is particularly useful if you want to create private functions (for example calling your internal APIs).
- Get started by reading the framework page
Deployment
ip2asn
function can be deployed with:
pip install bigfunctions
bigfun get ip2asn
bigfun deploy ip2asn
Requirements
ip2asn
uses the following secrets. Get them by reading the documentation link and store them in Google Secret Manager in the project where you deploy the function (and give Accessor role to the service account of the function):
name | description | documentation to get the secret |
---|---|---|
ipinfo_token |
IP Info Token | doc |
Examples¶
select bigfunctions.eu.ip2asn("152.216.7.110")
select bigfunctions.us.ip2asn("152.216.7.110")
select bigfunctions.europe_west1.ip2asn("152.216.7.110")
+------------------------------------------------------------------------+
| asn |
+------------------------------------------------------------------------+
| {"asn":"AS30313","domain":"irs.gov","name":"Internal Revenue Service"} |
+------------------------------------------------------------------------+
Use cases¶
You have a table of web server logs that includes the IP address of each client that made a request. You want to analyze these logs to understand the geographic distribution of your users at a network level (Autonomous System Number or ASN). ASNs represent blocks of IP addresses managed by a specific network operator (e.g., an internet service provider or a large organization).
Here's how ip2asn
could be used:
SELECT
request_time,
client_ip,
bigfunctions.us.ip2asn(client_ip) AS asn_info
FROM
`your_project.your_dataset.web_server_logs`;
This query would add a new column, asn_info
, to your log data. This column would contain a JSON string with information about the ASN associated with the client IP address, including the ASN number (asn
), domain (domain
), and name (name
) of the network. You could then use this ASN information for various analytical purposes:
- Geographic analysis: By aggregating data based on ASN, you can identify which networks (and therefore, potentially which geographic regions) are generating the most traffic to your website.
- Network performance analysis: You might observe performance issues related to specific ASNs, which could indicate problems with a particular internet service provider.
- Security analysis: Analyzing traffic patterns by ASN can help detect unusual activity that might be indicative of malicious actors operating within a certain network.
- Marketing and sales: Understanding the distribution of your users across different ASNs could inform targeted advertising campaigns.
You could further process the JSON string to extract the individual fields:
SELECT
request_time,
client_ip,
JSON_EXTRACT_SCALAR(bigfunctions.us.ip2asn(client_ip), '$.asn') AS asn,
JSON_EXTRACT_SCALAR(bigfunctions.us.ip2asn(client_ip), '$.name') AS asn_name
FROM
`your_project.your_dataset.web_server_logs`;
This revised query provides cleaner, separate columns for the ASN and its name, making it easier to use these values in further analysis, like grouping and filtering. Remember to select the correct BigQuery dataset location (e.g. bigfunctions.eu
for EU region) to match your data's location.
Need help or Found a bug?
Get help using ip2asn
The community can help! Engage the conversation on Slack
We also provide professional suppport.
Report a bug about ip2asn
If the function does not work as expected, please
- report a bug so that it can be improved.
- or open the discussion with the community on Slack.
We also provide professional suppport.