Created
December 31, 2020 07:15
-
-
Save bavovna/2b1cd559776727ec2461f9613edac2d0 to your computer and use it in GitHub Desktop.
lookup your IP in rust
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mod rxx; | |
fn main() -> Result<(), Box<dyn std::error::Error>> { | |
let v = rxx::my_ip()?; | |
println!("{}", v); // println!("{:#?}", v); | |
Ok(()) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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