Browse Source

r 0.1.6

master
syui 1 year ago
parent
commit
2f5449c868
No known key found for this signature in database GPG Key ID: ED2A0F5F1DA25512
  1. 30
      Cargo.lock
  2. 1
      Cargo.toml
  3. 14
      readme.md
  4. 24
      src/main.rs

30
Cargo.lock

@ -60,6 +60,16 @@ dependencies = [
"time 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "dns-lookup"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.69 (registry+https://github.com/rust-lang/crates.io-index)",
"socket2 0.3.12 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "env_logger"
version = "0.5.13"
@ -164,6 +174,11 @@ name = "quick-error"
version = "1.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "redox_syscall"
version = "0.1.56"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "regex"
version = "1.3.7"
@ -195,6 +210,17 @@ name = "smallvec"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "socket2"
version = "0.3.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.69 (registry+https://github.com/rust-lang/crates.io-index)",
"redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "termcolor"
version = "1.1.0"
@ -225,6 +251,7 @@ name = "udrs"
version = "0.1.4"
dependencies = [
"base64 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)",
"dns-lookup 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"pretty_env_logger 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
"seahorse 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
"url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
@ -292,6 +319,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de"
"checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
"checksum chrono 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)" = "80094f509cf8b5ae86a4966a39b3ff66cd7e2a3e594accec3743ff3fabeab5b2"
"checksum dns-lookup 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "8ea427e983abd535e5ea03dcf395b3a7ae4546f908c8c9e59cca36cf968f82ce"
"checksum env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)" = "15b0a4d2e39f8420210be8b27eeda28029729e2fd4291019455016c348240c38"
"checksum hermit-abi 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "61565ff7aaace3525556587bd2dc31d4a07071957be715e63ce7b1eccf51a8f4"
"checksum humantime 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "df004cfca50ef23c36850aaaa59ad52cc70d0e90243c3c7737a4dd32dc7a3c4f"
@ -306,11 +334,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "31010dd2e1ac33d5b46a5b413495239882813e0369f8ed8a5e266f173602f831"
"checksum pretty_env_logger 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "ed8d1e63042e889b85228620629b51c011d380eed2c7e0015f8a644def280c28"
"checksum quick-error 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0"
"checksum redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)" = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84"
"checksum regex 1.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "a6020f034922e3194c711b82a627453881bc4682166cabb07134a10c26ba7692"
"checksum regex-syntax 0.6.17 (registry+https://github.com/rust-lang/crates.io-index)" = "7fe5bd57d1d7414c6b5ed48563a2c855d995ff777729dcd91c369ec7fea395ae"
"checksum safemem 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ef703b7cb59335eae2eb93ceb664c0eb7ea6bf567079d843e09420219668e072"
"checksum seahorse 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "24ad40c7a40cb8a26a35098088edc42c29044f273645d9ff4d50b1853a176eaa"
"checksum smallvec 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c7cb5678e1615754284ec264d9bb5b4c27d2018577fd90ac0ceb578591ed5ee4"
"checksum socket2 0.3.12 (registry+https://github.com/rust-lang/crates.io-index)" = "03088793f677dce356f3ccc2edb1b314ad191ab702a5de3faf49304f7e104918"
"checksum termcolor 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb6bfa289a4d7c5766392812c0a1f4c1ba45afa1ad47803c11e1f407d846d75f"
"checksum thread_local 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d40c6d1b69745a6ec6fb1ca717914848da4b44ae29d9b3080cbee91d72a69b14"
"checksum time 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)" = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438"

1
Cargo.toml

@ -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
readme.md

@ -51,7 +51,7 @@ foo bar
```sh
$ udrs ud "https://github.com/ksk001100/seahorse" -l
/ksk001100/seahorse
ksk001100/seahorse
$ udrs ud "https://github.com/ksk001100/seahorse" -p
https
@ -59,3 +59,15 @@ 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
src/main.rs

@ -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();
@ -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());
}
@ -88,11 +102,18 @@ 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";
@ -100,7 +121,6 @@ mod tests {
let actual = url::percent_encoding::percent_decode(input.as_bytes()).decode_utf8().unwrap();
assert_eq!(expected, actual);
}
#[test]
fn base64_encode() {
let expected = "aGVsbG8gd29ybGQu";

Loading…
Cancel
Save