Last active
July 1, 2016 05:08
-
-
Save yantze/aa7e6447822cbe85692bfe0af3ad9cbe to your computer and use it in GitHub Desktop.
get pure ip from url
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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