Initial commit.
This commit is contained in:
commit
6485e0d24f
4 changed files with 1201 additions and 0 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
/target
|
1170
Cargo.lock
generated
Normal file
1170
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
13
Cargo.toml
Normal file
13
Cargo.toml
Normal file
|
@ -0,0 +1,13 @@
|
|||
[package]
|
||||
name = "getmyip"
|
||||
version = "0.1.0"
|
||||
authors = ["Kalle Carlbark <kalle.carlbark@kcbark.net>"]
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
reqwest = { version = "0.10" }
|
||||
tokio = { version = "0.2", features = ["full"] }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
17
src/main.rs
Normal file
17
src/main.rs
Normal file
|
@ -0,0 +1,17 @@
|
|||
use serde::{Deserialize};
|
||||
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct Ip {
|
||||
ip: String,
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let resp = reqwest::get("https://api.ipify.org?format=json")
|
||||
.await?;
|
||||
let body = resp.text().await?;
|
||||
let ip: Ip = serde_json::from_str(&body)?;
|
||||
println!("My IP {}", ip.ip);
|
||||
Ok(())
|
||||
}
|
Loading…
Reference in a new issue