vefcaddy.blogg.se

Bash script to get ip address
Bash script to get ip address







Got answer: ->HEADER<<- opcode: QUERY, status: NOERROR If you suspect a different issue (with the upstream provider, the command-line tool, or something else) then run the command without the +short option to reveal the details of the DNS query. If the command is not working for some reason, there may be a network problem. $ dig TXT. +shortĮxample alias that specifically requests an IPv4 address: # Īlias wanip6='dig TXT. +short -6' # Supports IPv6 + IPv4, use -4 or -6 to force one. # but has the benefit of working with private DNS proxies. # NOTE: This returns only an approximate IP from your block,

bash script to get ip address

Various DNS providers offer this service, including OpenDNS, Akamai, and Google Public DNS: # OpenDNS (since 2009) For example, when connecting over IPv6, it cannot return the A address. Note that it can only return the address used for the connection. To require the response be an IPv4 address, replace ANY with A for IPv6, replace it with AAAA. To prefer IPv4 or IPv6 connection specifically, use the -4 or -6 options accordingly. The ANY query type returns either an AAAA or an A record. +short (Display nothing except short form of answer) Perhaps alias it in your bashrc so it's easy to remember # Īlias wanip='dig +short'Īlias wanip4='dig +short -4'Īlias wanip6='dig AAAA +short -6' Using dig with an OpenDNS resolver: $ dig +short

bash script to get ip address

This method is inherently faster (be it only by a few milliseconds!).) tend to survive much longer and are more stable, more scalable, and generally more looked-after than whatever new hip whatismyip dot-com HTTP service is hot today. Historically, DNS services (Akamai, Google Public DNS, OpenDNS.The DNS response protocol is standardised (the format will stay compatible).

bash script to get ip address

Those change quite frequently (go down, change their name, put up ads, might change output format etc.). Some of them required parsing of the output, or relied on the User-Agent header to make the server respond in plain text. Most of the other answers below all involve going over HTTP to a remote server. I'd recommend getting it directly from a DNS server.









Bash script to get ip address