Skip to content

Instantly share code, notes, and snippets.

@turnipsoup
Last active April 27, 2022 19:03
Show Gist options
  • Save turnipsoup/bd554a7826512714d6bccde56c9fcf08 to your computer and use it in GitHub Desktop.
Save turnipsoup/bd554a7826512714d6bccde56c9fcf08 to your computer and use it in GitHub Desktop.
Learning harelang - made a quit and easy DNS query tool for a single hostname.
use fmt;
use strings;
use net::dial;
use net::ip;
use strings;
use os;
export fn main() void = {
if (len(os::args) < 2) {
fmt::println("Usage: get <hostname>")!;
os::exit(1);
};
getServerInfo(os::args[1]);
};
// Performs DNS query against passed URL and prints the Hostname and IP's
// To the screen
fn getServerInfo(url: str) void = {
const addr = dial::resolve("tcp", url, "dns") as ([]ip::addr, u16);
fmt::printfln("Host: {}", url)!;
for (let i = 0z; i < len(addr.0); i += 1) {
let a: str = net::ip::string(addr.0[i]);
let b: str = "IPv4";
if (len(a) > 16) {
b = "IPv6";
};
fmt::printfln("{}: {}", b, a)!;
};
};
// jheckt@box:~/code/ha|⇒ hare run get.ha google.com
// Host: google.com
// IPv6: 2a00:1450:400e:811::200e
// IPv4: 142.251.39.110
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment