[opensuse] How can I get the external IP on a script?
Hi, In order to get the external IP on a script I used (Dec 2015) this one liner: wget -qO - checkip.dyndns.org | cut -d":" -f2 | cut -d"<" -f1 and this is failing now (returns empty), but I'm unable (ie, too thick today) to see why. The output of the wget run is: cer@minas-tirith:~> wget -qO - checkip.dyndns.org <html><head><title>Current IP Check</title></head><body>Current IP Address: 2.141.215.163</body></html> cer@minas-tirith:~> Something has changed, no idea what. Meanwhile, looking on google, I got another simpler oneliner (from https://coderwall.com/p/lmi2jw/get-external-ip-in-a-script): curl http://icanhazip.com they also suggest using http://ifconfig.me/ip instead, but it fails: cer@minas-tirith:~> curl http://icanhazip.com 2.141.215.163 cer@minas-tirith:~> curl http://checkip.dyndns.org cer@minas-tirith:~> curl http://ifconfig.me/ip cer@minas-tirith:~> All sites work on a browser, but only http://icanhazip.com works on the CLI with curl. Why? -- Cheers / Saludos, Carlos E. R. (from 42.2 x86_64 "Malachite" (Minas Tirith))
On Wednesday 31 May 2017, Carlos E. R. wrote:
Hi,
In order to get the external IP on a script I used (Dec 2015) this one liner:
wget -qO - checkip.dyndns.org | cut -d":" -f2 | cut -d"<" -f1
and this is failing now (returns empty), but I'm unable (ie, too thick today) to see why. The output of the wget run is:
cer@minas-tirith:~> wget -qO - checkip.dyndns.org <html><head><title>Current IP Check</title></head><body>Current IP Address: 2.141.215.163</body></html> cer@minas-tirith:~>
Something has changed, no idea what.
Meanwhile, looking on google, I got another simpler oneliner (from https://coderwall.com/p/lmi2jw/get-external-ip-in-a-script):
curl http://icanhazip.com
they also suggest using http://ifconfig.me/ip instead, but it fails:
cer@minas-tirith:~> curl http://icanhazip.com 2.141.215.163 cer@minas-tirith:~> curl http://checkip.dyndns.org cer@minas-tirith:~> curl http://ifconfig.me/ip cer@minas-tirith:~>
All sites work on a browser, but only http://icanhazip.com works on the CLI with curl. Why?
I use this because I've had bad experiences with dyndns and friends: $ dig @resolver1.opendns.com myip.opendns.com +short In a script I'm using it like below, inclusive error handling and validating the IP. Also easy to change the actual method in case it will break anytime. ------------ #!/bin/sh isvalid_ip4() { local ip="$1" test -n "$ip" || return 1 ip -4 route get "$ip" >/dev/null || return 1 ping -W 1 -c1 "$ip" >/dev/null || return 1 } myip4_dig_opendns() { dig @resolver1.opendns.com myip.opendns.com +short } myip4_generic() { local myipfun="$1" local myip="" myip="$("$myipfun")" || return 1 isvalid_ip4 "$myip" || return 1 echo "$myip" } MYIP4=$(myip4_generic myip4_dig_opendns) if [ $? != 0 ]; then echo "error: unable to find out our public IPv4 address" 1>&2 exit 1 fi # do something with $MYIP4 ... ------------------------- cu, Rudi -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
On 2017-05-31 12:29, Ruediger Meier wrote:
On Wednesday 31 May 2017, Carlos E. R. wrote:
I use this because I've had bad experiences with dyndns and friends:
$ dig @resolver1.opendns.com myip.opendns.com +short
In a script I'm using it like below, inclusive error handling and validating the IP. Also easy to change the actual method in case it will break anytime.
Wow, that's a complex one :-) In the laptop I only log the external IP, I don't use it for anything, anyway. At home yes, I do use it; but I obtain the data querying my router instead. -- Cheers / Saludos, Carlos E. R. (from 42.2 x86_64 "Malachite" (Minas Tirith))
Carlos & Ruediger, et al -- ...and then Ruediger Meier said... % % On Wednesday 31 May 2017, Carlos E. R. wrote: % > ... % > wget -qO - checkip.dyndns.org | cut -d":" -f2 | cut -d"<" -f1 ... % > https://coderwall.com/p/lmi2jw/get-external-ip-in-a-script): % > % > curl http://icanhazip.com % > % > they also suggest using http://ifconfig.me/ip instead, but it fails: % > % > cer@minas-tirith:~> curl http://icanhazip.com % > 2.141.215.163 % > cer@minas-tirith:~> curl http://checkip.dyndns.org % > cer@minas-tirith:~> curl http://ifconfig.me/ip ... % % I use this because I've had bad experiences with dyndns and friends: % % $ dig @resolver1.opendns.com myip.opendns.com +short [snip] Wow! These are all great; I'm going to have to go poking. Because I'm apparently too thick-headed to go Googling, I just wrote my own little php script that checks the external IP in the web server vars and records that along with any IPs passed by the caller, which gives me something like Array ( [realname] => LNXTW8DT6667 [nickname] => att-2 [iflist] => fd0c:b6df:327:5449:7962:9bcc:c544:8165,fe80::20d7:3c0d:a6ae:f817,169.254.248.23,2602:306:301d: [remote_addr] => 99.1.220.169 [lastreport] => 2016-09-16 12:53:04 ) Array ( [realname] => samuel [nickname] => samuel [iflist] => fe80::b8c1:6ec:5d16:4d1d%2,10.0.5.199,2001:0:9d38:90d7:1a:200e:9743:645,fe80::1a:200e:9743:645% [remote_addr] => 104.188.249.186 [lastreport] => 2017-04-26 14:24:56 ) when I want to get back to, say, my house. It does the job. I've thought for years about handing my justpickone.net DNS off to someone to not only manage the static records but also just pick up any other locations (home, rental, in-laws, ...) that matter to me and get past my little kludge ... but I keep never getting around to it :-) HAND :-D -- David T-G See http://justpickone.org/davidtg/email/ See http://justpickone.org/davidtg/tofu.txt -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
On Wednesday 31 May 2017, David T-G wrote:
Carlos & Ruediger, et al --
...and then Ruediger Meier said... % % On Wednesday 31 May 2017, Carlos E. R. wrote: % > ... % > wget -qO - checkip.dyndns.org | cut -d":" -f2 | cut -d"<" -f1 ... % > https://coderwall.com/p/lmi2jw/get-external-ip-in-a-script): % > % > curl http://icanhazip.com % > % > they also suggest using http://ifconfig.me/ip instead, but it fails: % > % > cer@minas-tirith:~> curl http://icanhazip.com % > 2.141.215.163 % > cer@minas-tirith:~> curl http://checkip.dyndns.org % > cer@minas-tirith:~> curl http://ifconfig.me/ip ... % % I use this because I've had bad experiences with dyndns and friends: % % $ dig @resolver1.opendns.com myip.opendns.com +short [snip]
Wow! These are all great; I'm going to have to go poking.
Because I'm apparently too thick-headed to go Googling, I just wrote my own little php script that checks the external IP in the web server vars and records that along with any IPs passed by the caller, which gives me something like
Array ( [realname] => LNXTW8DT6667 [nickname] => att-2 [iflist] => fd0c:b6df:327:5449:7962:9bcc:c544:8165,fe80::20d7:3c0d:a6ae:f817,169. 254.248.23,2602:306:301d: [remote_addr] => 99.1.220.169 [lastreport] => 2016-09-16 12:53:04 ) Array ( [realname] => samuel [nickname] => samuel [iflist] => fe80::b8c1:6ec:5d16:4d1d%2,10.0.5.199,2001:0:9d38:90d7:1a:200e:9743:6 45,fe80::1a:200e:9743:645% [remote_addr] => 104.188.249.186 [lastreport] => 2017-04-26 14:24:56 )
when I want to get back to, say, my house. It does the job.
I've thought for years about handing my justpickone.net DNS off to someone to not only manage the static records but also just pick up any other locations (home, rental, in-laws, ...) that matter to me and get past my little kludge ... but I keep never getting around to it :-)
You could just add static CNAME records to the existing justpickone.net DNS and use any other external dyndns service for dynamic updates, like myhost.justpickone.net IN CNAME myhost.whatever.dyndns.domain I'm using Hurricane Electric Free DNS Management, https://dns.he.net/ cu, Rudi -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
Ruediger, et al -- ...and then Ruediger Meier said... % % On Wednesday 31 May 2017, David T-G wrote: % > ... % > I've thought for years about handing my justpickone.net DNS off to % > someone to not only manage the static records but also just pick up % > any other locations (home, rental, in-laws, ...) that matter to me % > and get past my little kludge ... but I keep never getting around to % > it :-) % % You could just add static CNAME records to the existing justpickone.net % DNS and use any other external dyndns service for dynamic updates, like % % myhost.justpickone.net IN CNAME myhost.whatever.dyndns.domain Hmmm... That's a pretty elegant idea, actually. Thanks! I may tinker with that. % % I'm using Hurricane Electric Free DNS Management, https://dns.he.net/ Good to know :-) % % cu, % Rudi Thanks again & HAND :-D -- David T-G See http://justpickone.org/davidtg/email/ See http://justpickone.org/davidtg/tofu.txt -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
On 05/31/2017 02:02 AM, Carlos E. R. wrote:
In order to get the external IP on a script I used (Dec 2015) this one liner:
wget -qO - checkip.dyndns.org | cut -d":" -f2 | cut -d"<" -f1
and this is failing now (returns empty), but I'm unable (ie, too thick today) to see why. The output of the wget run is:
That works for me. But then, I'm a paying customer of dyndns. Maybe they want a login of some kind ? -- After all is said and done, more is said than done.
On 2017-05-31 20:01, John Andersen wrote:
On 05/31/2017 02:02 AM, Carlos E. R. wrote:
In order to get the external IP on a script I used (Dec 2015) this one liner:
wget -qO - checkip.dyndns.org | cut -d":" -f2 | cut -d"<" -f1
and this is failing now (returns empty), but I'm unable (ie, too thick today) to see why. The output of the wget run is:
That works for me. But then, I'm a paying customer of dyndns. Maybe they want a login of some kind ?
No, it is working for me now, and fast, on my desktop computer. On my laptop it did not, for two days at least. desktop: cer@Telcontar:~> wget -qO - checkip.dyndns.org <html><head><title>Current IP Check</title></head><body>Current IP Address: X.X.X.X</body></html> laptop: <html><head><title>Current IP Check</title></head><body>Current IP Address: Y.Y.Y.Y</body></html> The responses are the same, the only difference is the IP number. I don't understand it. Maybe different versions of the apps. I'll log the versions here for comparing later: GNU Wget 1.14 built on linux-gnu. wget-1.14-8.3.1.x86_64 cut (GNU coreutils) 8.25 coreutils-8.25-1.4.x86_64 Perhaps a locale difference? LANG=en_US.utf8 LC_CTYPE=en_US.UTF-8 LC_NUMERIC=es_ES@euro LC_TIME=en_DK.UTF-8 LC_COLLATE=POSIX LC_MONETARY=es_ES@euro LC_MESSAGES="en_US.utf8" LC_PAPER=es_ES@euro LC_NAME=es_ES@euro LC_ADDRESS="en_US.utf8" LC_TELEPHONE=es_ES@euro LC_MEASUREMENT=es_ES@euro LC_IDENTIFICATION="en_US.utf8" LC_ALL= -- Cheers / Saludos, Carlos E. R. (from 42.2 x86_64 "Malachite" at Telcontar)
On 31.05.2017 22:19, Carlos E. R. wrote:
No, it is working for me now, and fast, on my desktop computer. On my laptop it did not, for two days at least.
desktop: cer@Telcontar:~> wget -qO - checkip.dyndns.org <html><head><title>Current IP Check</title></head><body>Current IP Address: X.X.X.X</body></html>
laptop: <html><head><title>Current IP Check</title></head><body>Current IP Address: Y.Y.Y.Y</body></html>
The responses are the same, the only difference is the IP number.
I don't understand it. Maybe different versions of the apps. I'll log the versions here for comparing later:
GNU Wget 1.14 built on linux-gnu. wget-1.14-8.3.1.x86_64 cut (GNU coreutils) 8.25 coreutils-8.25-1.4.x86_64
Perhaps a locale difference?
Just a thought: could it be that the laptop connects through a different router to the internet? Maybe using the WLAN of a neighbor or similar? -- Cahn's Axiom: When all else fails, read the instructions. -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
On 01.06.2017 10:12, Andreas Mahel wrote:
On 31.05.2017 22:19, Carlos E. R. wrote:
No, it is working for me now, and fast, on my desktop computer. On my laptop it did not, for two days at least.
desktop: cer@Telcontar:~> wget -qO - checkip.dyndns.org <html><head><title>Current IP Check</title></head><body>Current IP Address: X.X.X.X</body></html>
laptop: <html><head><title>Current IP Check</title></head><body>Current IP Address: Y.Y.Y.Y</body></html>
The responses are the same, the only difference is the IP number.
I don't understand it. Maybe different versions of the apps. I'll log the versions here for comparing later:
GNU Wget 1.14 built on linux-gnu. wget-1.14-8.3.1.x86_64 cut (GNU coreutils) 8.25 coreutils-8.25-1.4.x86_64
Perhaps a locale difference?
Just a thought: could it be that the laptop connects through a different router to the internet? Maybe using the WLAN of a neighbor or similar?
Or could it be that the laptop is configured to use an external proxy, or is tunneling through a vpn connection? -- Cahn's Axiom: When all else fails, read the instructions. -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
On 2017-06-01 10:12, Andreas Mahel wrote:
On 31.05.2017 22:19, Carlos E. R. wrote:
No, it is working for me now, and fast, on my desktop computer. On my laptop it did not, for two days at least.
desktop: cer@Telcontar:~> wget -qO - checkip.dyndns.org <html><head><title>Current IP Check</title></head><body>Current IP Address: X.X.X.X</body></html>
laptop: <html><head><title>Current IP Check</title></head><body>Current IP Address: Y.Y.Y.Y</body></html>
The responses are the same, the only difference is the IP number.
I don't understand it. Maybe different versions of the apps. I'll log the versions here for comparing later:
GNU Wget 1.14 built on linux-gnu. wget-1.14-8.3.1.x86_64 cut (GNU coreutils) 8.25 coreutils-8.25-1.4.x86_64
Perhaps a locale difference?
Just a thought: could it be that the laptop connects through a different router to the internet? Maybe using the WLAN of a neighbor or similar?
It certainly does, but that only means the IP is different. You can see above the output of wget on both cases, and it is exactly the same bar the IP numbers. Unless there are invisible chars. -- Cheers / Saludos, Carlos E. R. (from 42.2 x86_64 "Malachite" at Telcontar)
participants (6)
-
Andreas Mahel
-
Carlos E. R.
-
Carlos E. R.
-
David T-G
-
John Andersen
-
Ruediger Meier