Spaces:
Running
Running
File size: 5,611 Bytes
90531db 7fddf3d 90531db 7fddf3d 90531db 7fddf3d 90531db 7fddf3d 90531db 7fddf3d 90531db 7fddf3d 90531db 7fddf3d 90531db 7fddf3d 90531db 7fddf3d 90531db 7fddf3d 90531db 7fddf3d 90531db 7fddf3d 90531db 7fddf3d 90531db 7fddf3d 90531db 7fddf3d 90531db 7fddf3d 90531db | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | """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"],
}
}
|