bigfunctions > ip2asn
ip2asn¶
Call or Deploy ip2asn
?
✅ You can call this ip2asn
bigfunction directly from your Google Cloud Project (no install required).
- This
ip2asn
function is deployed inbigfunctions
GCP project in 39 datasets for all of the 39 BigQuery regions. You need to use the dataset in the same region as your datasets (otherwise you may have a function not found error). - Function is public, so it can be called by anyone. Just copy / paste examples below in your BigQuery console. It just works!
- You may prefer to deploy the BigFunction in your own project if you want 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). Discover the framework
Public BigFunctions Datasets:
Region | Dataset |
---|---|
eu |
bigfunctions.eu |
us |
bigfunctions.us |
europe-west1 |
bigfunctions.europe_west1 |
asia-east1 |
bigfunctions.asia_east1 |
... | ... |
Description¶
Signature
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.
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"} |
+------------------------------------------------------------------------+
Need help using ip2asn
?
The community can help! Engage the conversation on Slack
For professional suppport, don't hesitate to chat with us.
Found a bug using 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.
For professional suppport, don't hesitate to chat with us.
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.
Spread the word¶
BigFunctions is fully open-source. Help make it a success by spreading the word!