Python library to detect hosting provider based on IP, FQDN, and network information
Project description
IP2Provider
Python library to guess a hosting provider id from hints you already have (IP, hostname, RDAP-style network fields, DNS) or from a target string after live resolution (DNS + RDAP).
Installation
pip install ip2provider
Runtime dependencies: dnspython, ipwhois, tldextract (see pyproject.toml).
Matching API (find)
Load rules (default: bundled ip2provider/data/provider.json), then score every known provider and return the one with highest total confidence (sum of matching rule weights).
from ip2provider import IP2Provider
provider = IP2Provider()
result = provider.find(
ip="192.168.1.1",
fqdn="server.example.com",
network_name="EXAMPLE-NET",
network_contact_email="abuse@example.com",
ns_server="ns1.example.com",
asn="24940",
asname="SOME-AS, US",
organization="Example Org",
)
if result:
print(result["provider"], result["confidence"])
All arguments are optional; pass any subset. Plural forms (ips, fqdns, network_contact_emails, ns_servers, asns, asnames, organizations) let you pass several values; the matcher stops after the first hit per rule group where that is defined.
Inputs and rule types in provider.json:
find(...) argument(s) |
Signal key in rules | Match style |
|---|---|---|
network_name |
netname |
regex on netname (RDAP/WHOIS) |
fqdn, fqdns |
ptr |
regex on host / PTR name |
network_contact_email(s) |
netmail |
regex on e-mail(s) from RDAP |
ip, ips |
ip |
exact string |
ns_server, ns_servers |
ns |
regex on NS hostnames |
asn, asns |
asn |
exact numeric AS (JSON keys are digit strings, e.g. "24940") |
asname, asnames |
asname |
regex on AS description (same idea as asn_description in RDAP) |
organization(s) |
org |
regex on organisation string from RDAP |
Resolution API (collect_evidence, resolve_and_find)
For a user-supplied IP or hostname, the library can gather evidence (PTR, A/AAAA, NS, RDAP: netname, e-mails, ASN, AS name, org) and then call find with the right kwargs.
from ip2provider import IP2Provider, collect_evidence, resolve_and_find
prov = IP2Provider()
ev = collect_evidence("8.8.8.8", dns_timeout=5.0)
print(ev.to_find_kwargs())
out = resolve_and_find(
prov,
"example.com",
dns_timeout=5.0,
min_agreeing_signals=2,
require_verified=False,
)
# out: provider, confidence, evidence, per_signal, agreement, verified, errors
resolve_and_find returns how many signal groups (ip, fqdn, network name, e-mail, ns, asn, asname, org) agree on the winning provider, so you can require multiple independent matches.
Custom rules file
IP2Provider(rules_path="/path/to/provider.json")
The file must be v1 JSON:
versionmust be1.providersis a non-empty array; each item hasname(id returned asresult["provider"]) andsignals(a map of signal name → map ofpattern→ integer weight).
Regex signals use Python re with re.IGNORECASE. Exact maps are used for ip and asn (only digit keys for asn).
Example (abbreviated):
{
"version": 1,
"providers": [
{
"name": "example.com",
"signals": {
"netname": { ".*EXAMPLE.*": 100 },
"ptr": { ".*\\.example\\.com$": 100 },
"netmail": { "@example.com": 40 },
"ns": { ".*ns\\.example\\..*": 30 },
"asn": { "12345": 50 },
"asname": { ".*EXAMPLE-AS.*": 40 },
"org": { ".*Example Inc.*": 20 }
}
}
]
}
Optional: set "$schema": "./provider.v1.schema.json" next to a copy of ip2provider/data/provider.v1.schema.json for editor validation.
A one-off migrator for the old root-object format lives at scripts/migrate_provider_json_v1.py.
Development
pip install -e ".[dev]"
pytest
jsonschema (dev) validates the bundled provider.json against provider.v1.schema.json in tests.
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ip2provider-0.2.1.tar.gz.
File metadata
- Download URL: ip2provider-0.2.1.tar.gz
- Upload date:
- Size: 19.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b5d0f246f673dbd2e8b7ba4d6a42819a57b04fc667a4008f83c05c217797a5b6
|
|
| MD5 |
98231324e17704eefbfcba865128571b
|
|
| BLAKE2b-256 |
957d93f5af9d179f7148d9935485c8c85b43a2ffc1fa5105133107f5c28842ab
|
Provenance
The following attestation bundles were made for ip2provider-0.2.1.tar.gz:
Publisher:
publish.yml on aredoff/ip2provider
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ip2provider-0.2.1.tar.gz -
Subject digest:
b5d0f246f673dbd2e8b7ba4d6a42819a57b04fc667a4008f83c05c217797a5b6 - Sigstore transparency entry: 1369706890
- Sigstore integration time:
-
Permalink:
aredoff/ip2provider@84dc5305efeabc9c7faeabcec9b97fde56932263 -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/aredoff
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@84dc5305efeabc9c7faeabcec9b97fde56932263 -
Trigger Event:
push
-
Statement type:
File details
Details for the file ip2provider-0.2.1-py3-none-any.whl.
File metadata
- Download URL: ip2provider-0.2.1-py3-none-any.whl
- Upload date:
- Size: 17.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
91307b7daece7a1f71c893fe339a0bd52c1c81ca9528d45b9d669726318492e5
|
|
| MD5 |
9a8f027a804702b96508ce6c7addcb2d
|
|
| BLAKE2b-256 |
42273e60824fe5d29dfd89d2a8121f6f467afe11f402fb641c9226fd58e97bba
|
Provenance
The following attestation bundles were made for ip2provider-0.2.1-py3-none-any.whl:
Publisher:
publish.yml on aredoff/ip2provider
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ip2provider-0.2.1-py3-none-any.whl -
Subject digest:
91307b7daece7a1f71c893fe339a0bd52c1c81ca9528d45b9d669726318492e5 - Sigstore transparency entry: 1369707111
- Sigstore integration time:
-
Permalink:
aredoff/ip2provider@84dc5305efeabc9c7faeabcec9b97fde56932263 -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/aredoff
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@84dc5305efeabc9c7faeabcec9b97fde56932263 -
Trigger Event:
push
-
Statement type: