-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinspect.zig
More file actions
29 lines (24 loc) · 796 Bytes
/
inspect.zig
File metadata and controls
29 lines (24 loc) · 796 Bytes
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
const std = @import("std");
const maxminddb = @import("maxminddb");
pub fn main() !void {
var gpa: std.heap.DebugAllocator(.{}) = .init;
const allocator = gpa.allocator();
defer _ = gpa.detectLeaks();
var args = std.process.args();
_ = args.next();
const db_path = args.next() orelse "test-data/test-data/GeoIP2-City-Test.mmdb";
const ip = args.next() orelse "89.160.20.128";
var db = try maxminddb.Reader.mmap(allocator, db_path);
defer db.unmap();
const result = try db.lookup(
allocator,
maxminddb.any.Value,
try std.net.Address.parseIp(ip, 0),
.{},
) orelse {
std.debug.print("{s}: not found\n", .{ip});
return;
};
defer result.deinit();
std.debug.print("{f}\n", .{result.value});
}