2

I tried using nslookup but I'm unable to parse the result :

My current output :

nslookup -norecurse myip.opendns.com resolver1.opendns.com
Serveur :   resolver1.opendns.com
Address:  208.67.222.222

Réponse ne faisant pas autorité :
Nom :    myip.opendns.com
Address:  X.X.X.X

I just want the IP X.X.X.X

I tried using | select without any success, maybe the good way, or not ...

Thanks for your help, note that the goal is just to get my public ip in a easy way without any dependancies and quickly, an answer without nslookup or powershell can make the job.

2

2 Answers 2

2

Try something like

Resolve-DnsName myip.opendns.com -server resolver1.opendns.com -type A | select -expand IP4Address

1
  • It's work perfectly, awesome ! I think that's the quicker way to get public IP address.
    – profy
    Oct 30, 2019 at 16:34
1

You can also use one of the many free REST APIs that provide this information rather than making DNS query (which has the downside of not working if you don't use dynamic DNS). Here's an example for one of the first ones I found.

Invoke-RestMethod https://api.ipify.org
1
  • Thanks this way works perfectly, it's the simpliest, but not as speedy as pure DNS request.
    – profy
    Oct 30, 2019 at 16:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.