krz/domain-dig
an ios app for DNS & SSL analysis
clone: git clone https://gitbay.org/krz/domain-dig.git
v1.5.0: DomainDig/IPGeolocationService.swift · raw
1import Foundation
2
3struct IPGeolocationService {
4 static func lookup(ip: String) async throws -> IPGeolocation {
5 let url = URL(string: "https://ipapi.co/\(ip)/json/")!
6 let request = URLRequest(url: url, timeoutInterval: 10)
7
8 let (data, response) = try await URLSession.shared.data(for: request)
9
10 guard let httpResponse = response as? HTTPURLResponse,
11 httpResponse.statusCode == 200 else {
12 throw URLError(.badServerResponse)
13 }
14
15 return try JSONDecoder().decode(IPGeolocation.self, from: data)
16 }
17}