Spaces:
Running
Running
Download src/models/ip.py from reputeradar/ioc-core: direct link, hf CLI and curl.
- Browser
- Download file 5.61 kB
-
https://huggingface.co/spaces/reputeradar/ioc-core/resolve/main/src/models/ip.py
- Command line
-
hf download hf://spaces/reputeradar/ioc-core/src/models/ip.py
-
curl -L -o ip.py https://huggingface.co/spaces/reputeradar/ioc-core/resolve/main/src/models/ip.py
5.61 kB
| """Pydantic models for IP reputation analysis.""" | |
| from pydantic import BaseModel, Field | |
| class AbuseIPDBResult(BaseModel): | |
| """Result model for AbuseIPDB IP analysis with all available fields.""" | |
| ip_address: str = Field(..., description="IP address analyzed") | |
| is_private: bool = Field( | |
| default=False, description="Whether the IP is a private/reserved address" | |
| ) | |
| is_public: bool | None = Field(None, description="Whether the IP is public") | |
| ip_version: int | None = Field(None, description="IP version (4 or 6)") | |
| is_whitelisted: bool | None = Field( | |
| None, description="Whether the IP is whitelisted" | |
| ) | |
| abuse_confidence_score: int | None = Field( | |
| None, description="Abuse confidence score (0-100)", ge=0, le=100 | |
| ) | |
| country_code: str | None = Field(None, description="Two-letter country code") | |
| country_name: str | None = Field(None, description="Full country name") | |
| usage_type: str | None = Field(None, description="Usage type of the IP") | |
| isp: str | None = Field(None, description="Internet Service Provider") | |
| domain: str | None = Field(None, description="Domain associated with the IP") | |
| hostnames: str | None = Field(None, description="Hostnames associated with the IP") | |
| is_tor: bool | None = Field(None, description="Whether the IP is a Tor exit node") | |
| total_reports: int | None = Field(None, description="Total number of abuse reports") | |
| num_distinct_users: int | None = Field( | |
| None, description="Number of distinct users who reported" | |
| ) | |
| last_reported_at: str | None = Field(None, description="Timestamp of last report") | |
| error: str | None = Field(None, description="Error message if analysis failed") | |
| class Config: | |
| json_schema_extra = { | |
| "example": { | |
| "ip_address": "8.8.8.8", | |
| "is_private": False, | |
| "is_public": True, | |
| "ip_version": 4, | |
| "is_whitelisted": True, | |
| "abuse_confidence_score": 0, | |
| "country_code": "US", | |
| "country_name": "United States", | |
| "usage_type": "Data Center/Web Hosting/Transit", | |
| "isp": "Google LLC", | |
| "domain": "google.com", | |
| "hostnames": "dns.google", | |
| "is_tor": False, | |
| "total_reports": 0, | |
| "num_distinct_users": 0, | |
| "last_reported_at": None, | |
| "error": None, | |
| } | |
| } | |
| class VirusTotalIPResult(BaseModel): | |
| """Result model for VirusTotal IP analysis with all available fields.""" | |
| vt_ip_address: str = Field(..., description="IP address analyzed") | |
| is_private: bool = Field( | |
| default=False, description="Whether the IP is a private/reserved address" | |
| ) | |
| vt_country: str | None = Field(None, description="Country code from VirusTotal") | |
| vt_continent: str | None = Field(None, description="Continent code") | |
| vt_asn: int | None = Field(None, description="Autonomous System Number") | |
| vt_as_owner: str | None = Field(None, description="AS owner name") | |
| vt_network: str | None = Field(None, description="Network CIDR") | |
| vt_malicious_count: int | None = Field( | |
| None, description="Number of engines flagging as malicious", ge=0 | |
| ) | |
| vt_suspicious_count: int | None = Field( | |
| None, description="Number of engines flagging as suspicious", ge=0 | |
| ) | |
| vt_harmless_count: int | None = Field( | |
| None, description="Number of engines flagging as harmless", ge=0 | |
| ) | |
| vt_undetected_count: int | None = Field( | |
| None, description="Number of engines with no detection", ge=0 | |
| ) | |
| vt_total_engines: int | None = Field( | |
| None, description="Total number of engines that scanned", ge=0 | |
| ) | |
| vt_reputation_score: int | None = Field( | |
| None, description="VirusTotal reputation score" | |
| ) | |
| vt_last_analysis_date: str | None = Field( | |
| None, description="Last analysis date (ISO format)" | |
| ) | |
| vt_tags: list[str] | None = Field(None, description="Tags associated with the IP") | |
| vt_whois: str | None = Field(None, description="WHOIS information") | |
| error: str | None = Field(None, description="Error message if analysis failed") | |
| class Config: | |
| json_schema_extra = { | |
| "example": { | |
| "vt_ip_address": "8.8.8.8", | |
| "is_private": False, | |
| "vt_country": "US", | |
| "vt_continent": "NA", | |
| "vt_asn": 15169, | |
| "vt_as_owner": "GOOGLE", | |
| "vt_network": "8.8.8.0/24", | |
| "vt_malicious_count": 0, | |
| "vt_suspicious_count": 0, | |
| "vt_harmless_count": 70, | |
| "vt_undetected_count": 15, | |
| "vt_total_engines": 85, | |
| "vt_reputation_score": 100, | |
| "vt_last_analysis_date": "2026-01-10T12:00:00Z", | |
| "vt_tags": ["google"], | |
| "vt_whois": None, | |
| "error": None, | |
| } | |
| } | |
| class IPReputationResult(BaseModel): | |
| """Combined IP reputation result from multiple sources.""" | |
| abuseipdb: AbuseIPDBResult = Field(..., description="AbuseIPDB analysis results") | |
| virustotal: VirusTotalIPResult = Field( | |
| ..., description="VirusTotal analysis results" | |
| ) | |
| class Config: | |
| json_schema_extra = { | |
| "example": { | |
| "abuseipdb": AbuseIPDBResult.Config.json_schema_extra["example"], | |
| "virustotal": VirusTotalIPResult.Config.json_schema_extra["example"], | |
| } | |
| } | |