I created a tiny library to get the currently-used, public IP address!

I needed this for another script I'm writing and thought others might find it useful, too.

The only dependency is Regex, because I couldn't find a function in the std lib that allowed me to parse the IP.

@kevin nice library and fortunately one of a few that don't directly pull in reqwest or hyper for making a few small http calls 👍.

Regarding IP parsing, the Ipv4Addr implements FromStr so you should be able to simply call parse on the string.

@dnaka91 Thank you!

The only reason why I made this was the fact all other libs use reqwest or hyper :D

Regarding FromStr: This doesn't work because the returned string from making the HTTP call is not a plain IP address but a string like "Your IP Address is X" or JSON.

@dnaka91 I've been thinking and I came up with a way of parsing (and validating) the IP without regex, using a custom lookup logic and then IPv4Addr::from_str() to validate the IP I parsed is correct!

Thank you for your input, I could get rid of the regex dependency. :)

Sign in to participate in the conversation
Mastodon is a instance for everyone who is part of bullgit. 🎉