Get public IP from bash

2»

Comments

  • ehabehab Content Writer

    @atomi said:

    is there "the simple" way to show all the payload... i mean if i did a get/post request , i am interested in seeing in json format the payload "echo back in json"

  • atomiatomi OG
    edited March 2023

    @ehab said:

    @atomi said:

    is there "the simple" way to show all the payload... i mean if i did a get/post request , i am interested in seeing in json format the payload "echo back in json"

    well there is echo module for nginx which definitely help you with more complex json. If all you want is IP in json format you could try something like this with pure nginx(untested)

    location /json {
      default_type application/json;
      return 200 '{"ipaddress":"'$remote_addr'"}';
    }
    
    Thanked by (1)FrankZ
  • It's also possible via DNS:

    For IPv4:

    dig -4 +short -t a myip.opendns.com @resolver1.opendns.com
    

    And for IPv6:

    dig -6 +short -t aaaa myip.opendns.com @resolver1.opendns.com
    
    Thanked by (2)FrankZ carlin0
  • host -4 myip.opendns.com resolver1.opendns.com
    host -6 myip.opendns.com resolver1.opendns.com

  • curl ip.sb
    
  • curl ipinfo.io is the most useful

  • dfroedfroe Services Provider

    You can also avoid all the HTTP 'overhead' by using a simple DNS query to achieve the same:

    alias myip4="dig @208.67.220.220  @208.67.222.222  myip.opendns.com A    +short"
    alias myip6="dig @2620:119:35::35 @2620:119:53::53 myip.opendns.com AAAA +short"
    
    Thanked by (3)ehab flips tjn

    it-df.net: IT-Service David Froehlich | Individual network and hosting solutions | AS39083 | RIPE LIR services (IPv4, IPv6, ASN)

Sign In or Register to comment.