Prerequisites
- A Swift 5.9+ project with
ipapi-swiftadded - A free ip-api.io API key
Score an IP with riskScore
Returns a score (0–100) and a human riskLevel, plus the
factors that drove it. Use riskScore() for the caller's IP.
let client = IpApiClient(apiKey: ProcessInfo.processInfo.environment["IP_API_IO_KEY"]!)
let risk = try await client.riskScore(ip: "185.220.101.1")
print(risk.score) // 88.0
print(risk.riskLevel) // "high"
if let ip = risk.factors.ip {
print(ip.isTorNode, ip.isDatacenter)
}
if risk.score >= 75 {
// block, or send to manual review / step-up auth
} Score an email with emailRiskScore
Same 0–100 scale, driven by email signals (disposable provider, invalid syntax). Use it to grade leads or gate sign-ups by address quality.
let risk = try await client.emailRiskScore(email: "user@mailinator.com")
print(risk.score, risk.riskLevel) // 90.0 high
if let email = risk.factors.email {
print(email.isDisposable) // true
} Raw signals with ipReputation
Returns the underlying reputation data for an IP — use it when you want the source signals rather than a computed score.
let reputation = try await client.ipReputation(ip: "185.220.101.1")
print(reputation)