Skip to content

Instantly share code, notes, and snippets.

@yantze
Last active July 1, 2016 05:08
Show Gist options
  • Save yantze/aa7e6447822cbe85692bfe0af3ad9cbe to your computer and use it in GitHub Desktop.
Save yantze/aa7e6447822cbe85692bfe0af3ad9cbe to your computer and use it in GitHub Desktop.
get pure ip from url
#!/bin/sh
# get pure ip from url
function ipurl() {
echo $1 |
sed -e 's/^.*:\/\/\(.*\)/\1/g' | # remove http(s)://
awk -F/ '{print $1}' | # remove /query/abc?a=b
xargs ping -c 1 -t 1 | # -c only send one package, -t timeout 1s
sed -n '1p' | # result: get first line
sed -e 's/^.*(\([0-9\.]\{7,\}\)).*/\1/g' # get ip in the first line
}
# example
# $ ipurl https://github.com/yantze
# 192.30.253.113
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment