Skip to content

Instantly share code, notes, and snippets.

@bavovna
Created December 31, 2020 07:15
Show Gist options
  • Save bavovna/2b1cd559776727ec2461f9613edac2d0 to your computer and use it in GitHub Desktop.
Save bavovna/2b1cd559776727ec2461f9613edac2d0 to your computer and use it in GitHub Desktop.
lookup your IP in rust
mod rxx;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let v = rxx::my_ip()?;
println!("{}", v); // println!("{:#?}", v);
Ok(())
}
use std::collections::HashMap;
pub fn my_ip() -> Result<String, Box<dyn std::error::Error>>{
let resp = reqwest::blocking::get("https://httpbin.org/ip")?
.json::<HashMap<String, String>>()?;
let res = resp.get("origin").unwrap();
Ok(res.to_string())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment