Skip to content

Commit

Permalink
r 0.1.6
Browse files Browse the repository at this point in the history
  • Loading branch information
syui committed May 24, 2020
1 parent 7165a58 commit 2f5449c
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 3 deletions.
30 changes: 30 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ url = "1.7"
pretty_env_logger = "0.2"
base64 = "0.9.2"
seahorse = "0.7.1"
dns-lookup = "1.0.2"
14 changes: 13 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,23 @@ foo bar

```sh
$ udrs ud "https://github.com/ksk001100/seahorse" -l
/ksk001100/seahorse
ksk001100/seahorse

$ udrs ud "https://github.com/ksk001100/seahorse" -p
https

$ udrs ud "https://github.com/ksk001100/seahorse" -d
github.com
```

### v0.1.6

```sh
# domain -> ip address (v4)
$ udrs ud "https://github.com" -i
V4(52.192.72.89:443)

$ dig github.com
52.192.72.89
```

24 changes: 22 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::env;
use seahorse::{App, Command, Context, Flag, FlagType};
use url::percent_encoding::percent_decode;
use url::{Url, Position};
use dns_lookup::{getaddrinfo, AddrInfoHints, SockType};

fn main() {
let args: Vec<String> = env::args().collect();
Expand Down Expand Up @@ -54,6 +55,19 @@ fn ud_a(c: &Context) {
println!("{}", url.domain().unwrap());
} else if c.bool_flag("protocol") {
println!("{}", url.scheme());
} else if c.bool_flag("ip") {
let hostname = url.domain().unwrap();
let service = url.scheme();
let hints = AddrInfoHints {
socktype: SockType::Stream.into(),
.. AddrInfoHints::default()
};
let sockets =
getaddrinfo(Some(hostname), Some(service), Some(hints))
.unwrap().collect::<std::io::Result<Vec<_>>>().unwrap();
for socket in sockets {
println!("{:?}", socket.sockaddr);
}
} else {
println!("{}", percent_decode(c.args[0].as_bytes()).decode_utf8().unwrap());
}
Expand Down Expand Up @@ -88,19 +102,25 @@ fn ud_c() -> Command {
)
.alias("p"),
)
.flag(
Flag::new(
"ip",
"cli ud [url...] --ip(-i)",
FlagType::Bool,
)
.alias("i"),
)
}

#[cfg(test)]
mod tests {

#[test]
fn decode_space_ok() {
let expected = "foo bar";
let input = "foo%20bar";
let actual = url::percent_encoding::percent_decode(input.as_bytes()).decode_utf8().unwrap();
assert_eq!(expected, actual);
}

#[test]
fn base64_encode() {
let expected = "aGVsbG8gd29ybGQu";
Expand Down

0 comments on commit 2f5449c

Please sign in to comment.