External IP via command line

I wrote a small batch script using that method a while ago (useful for running via ScreenConnect or similar remote support software):
Code:
FOR /F "tokens=1,2 delims= " %%A IN ('nslookup myip.opendns.com resolver1.opendns.com') DO IF "%%A"=="Address:" SET EXTIP=%%B
set /p=%EXTIP%<NUL|clip
msg * /time:5 "The external IP ("%EXTIP%") has been copied to the clipboard."

It extracts the IP address, copies it to the clipboard then displays a message (for a predefined number of seconds):

HSmnQmM.png
 
I wrote a small batch script using that method
I did the same for Linux.
Code:
#!/bin/bash
extip=$(nslookup myip.opendns.com. resolver1.opendns.com | grep "Address" | grep -v "#53" | cut -d' ' -f2)
printf $extip | xclip -sel c
wall "external ip address "$extip" copied to clipboard"
Note: xclip isn't installed by default on some distros.
 
Back
Top