Dieser Befehl gibt meine IP-Adresse mit zusätzlichen Informationen zurück.Wie bekomme ich meine öffentliche IP-Adresse in einem Shell-Skript?
dig @resolver1.opendns.com myip.opendns.com
; <<>> DiG 9.6-ESV-R4-P3 <<>> @resolver1.opendns.com myip.opendns.com
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 48206
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;myip.opendns.com. IN A
;; ANSWER SECTION:
myip.opendns.com. 0 IN A 122.167.119.178
;; Query time: 199 msec
;; SERVER: 208.67.222.222#53(208.67.222.222)
;; WHEN: Fri May 18 11:46:51 2012
;; MSG SIZE rcvd: 50
Ich möchte nur meine IP-Adresse daraus extrahieren. Wie kann ich meine IP-Adresse aus dem Ausgang extrahieren?
das folgende funktioniert für mich "dig @ resolver1.opendns.com myip.opendns.com | grep^myip.opendns.com | tr '\ t': | cut -d: -f5 " –
auch versuchen curl ifconfig.me – rampr