Initial commit.

This commit is contained in:
Kalle Carlbark 2020-03-02 22:28:15 +01:00
commit 6485e0d24f
No known key found for this signature in database
GPG key ID: 5E4BAB01A57CDD62
4 changed files with 1201 additions and 0 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/target

1170
Cargo.lock generated Normal file

File diff suppressed because it is too large Load diff

13
Cargo.toml Normal file
View 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
View 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(())
}