Now i'm using a desktop gadget, but maybe it could be displayed in the status bar or using some plugin?
Do you need to see it all the time? (Why?) If not, what about a simple botton/hotkey which display it when activated?
No, not really. This is more some toy thing. But since it might be easy to obtain (from ipconfig), why not? But you're right, a hotkey would be also ok. But where would the ip show?
Hey, the following button should do what you need. Left click copies your external IP to the clipboard. Right click copies your local network IP to the clipboard. Enjoy.
<?xml version="1.0"?>
<button backcol="none" display="both" textcol="none" type="three_button">
<label>Get IP Address</label>
<icon1>#default:networkdrive</icon1>
<button backcol="none" display="both" textcol="none">
<label>Get IP Address</label>
<tip>Get Remote IP Address</tip>
<icon1>#default:networkdrive</icon1>
<function type="normal">
<instruction>@script jscript</instruction>
<instruction />
<instruction>var endpoint = "http://automation.whatismyip.com/n09230945.asp";</instruction>
<instruction>function getRemote() {</instruction>
<instruction> var xhr = new ActiveXObject('MSXML2.ServerXMLHTTP');</instruction>
<instruction> xhr.open('GET', endpoint, false);</instruction>
<instruction> xhr.send();</instruction>
<instruction> if (xhr.readyState !== 4)</instruction>
<instruction> throw new Error('REQUEST INCOMPLETE');</instruction>
<instruction> </instruction>
<instruction> if (xhr.status !== 200)</instruction>
<instruction> throw new Error('HTTP STATUS: ' + xhr.status);</instruction>
<instruction> </instruction>
<instruction> return xhr.responseText;</instruction>
<instruction>}</instruction>
<instruction />
<instruction>function setClipboard(txt) {</instruction>
<instruction> var wsh = new ActiveXObject("WScript.Shell");</instruction>
<instruction> wsh.Run("cmd.exe /c echo " + txt + " | clip", 0, true);</instruction>
<instruction>}</instruction>
<instruction />
<instruction>setClipboard(getRemote());</instruction>
</function>
</button>
<button backcol="none" display="both" textcol="none">
<label>Get IP Address</label>
<tip>Get Local IP Address</tip>
<icon1>#default:networkdrive</icon1>
<function type="normal">
<instruction>@script jscript</instruction>
<instruction />
<instruction>function getLocal() {</instruction>
<instruction> var objWMIService = GetObject( "winmgmts://./root/CIMV2" );</instruction>
<instruction> var colItems = objWMIService.ExecQuery( "SELECT * FROM Win32_NetworkAdapterConfiguration WHERE MACAddress > '' AND IPEnabled = TRUE" );</instruction>
<instruction> var enumItems = new Enumerator(colItems);</instruction>
<instruction> var addresses = [];</instruction>
<instruction> for ( ; !enumItems.atEnd(); enumItems.moveNext())</instruction>
<instruction> addresses.push(enumItems.item().IPAddress.toArray()[0]);</instruction>
<instruction> return addresses.join(" ");</instruction>
<instruction>}</instruction>
<instruction />
<instruction>function setClipboard(txt) {</instruction>
<instruction> var wsh = new ActiveXObject("WScript.Shell");</instruction>
<instruction> wsh.Run("cmd.exe /c echo " + txt + " | clip", 0, true);</instruction>
<instruction>}</instruction>
<instruction />
<instruction>setClipboard(getLocal());</instruction>
</function>
</button>
</button>
Note: Didn't feel like trying to figure out if the Clipboard interface was accessible, so I just used that trick.
Thanks a lot! I don´t use external proxies at the moment, but it´s useful to have.
This is an updated version for the "copy local/external" ip to clipboard dual-button:
- using an alternative service to return ip, as i could not get "whatismyip" to work
- no more additional blanks and linefeeds in resulting clipboard content
<?xml version="1.0"?>
<button backcol="none" display="both" textcol="none" type="three_button">
<label>Get IP Address</label>
<icon1>#default:networkdrive</icon1>
<button backcol="none" display="both" textcol="none">
<label>Get IP Address (external)</label>
<tip>Get IP Address (external)</tip>
<icon1>#default:networkdrive</icon1>
<function type="normal">
<instruction>@script jscript</instruction>
<instruction />
<instruction>var endpoint = "http://198.101.241.44"; // http://www.icanhazip.com/</instruction>
<instruction>function getRemote() {</instruction>
<instruction> var xhr = new ActiveXObject('MSXML2.XMLHTTP');</instruction>
<instruction> xhr.open('GET', endpoint, false);</instruction>
<instruction> xhr.send();</instruction>
<instruction> if (xhr.readyState !== 4)</instruction>
<instruction> throw new Error('REQUEST INCOMPLETE');</instruction>
<instruction />
<instruction> if (xhr.status !== 200)</instruction>
<instruction> throw new Error('HTTP STATUS: ' + xhr.status);</instruction>
<instruction />
<instruction> return xhr.responseText;</instruction>
<instruction>}</instruction>
<instruction />
<instruction>function setClipboard(txt) {</instruction>
<instruction> txt = txt.replace(/\n/g,"");</instruction>
<instruction> txt = txt.replace(/\r/g,"");</instruction>
<instruction> var wsh = new ActiveXObject("WScript.Shell");</instruction>
<instruction> cmd = "cmd.exe /c echo.|set /p =" + txt + "| clip" //this is a nolinefeed echo workaround</instruction>
<instruction> //cmd = "cmd.exe /c echo " + txt + " | clip"</instruction>
<instruction> result = wsh.Run(cmd, 0, true);</instruction>
<instruction>}</instruction>
<instruction />
<instruction>ip = getRemote();</instruction>
<instruction>setClipboard( ip );</instruction>
</function>
</button>
<button backcol="none" display="both" textcol="none">
<label>Get IP Address (local)</label>
<tip>Get IP Address (local)</tip>
<icon1>#default:networkdrive</icon1>
<function type="normal">
<instruction>@script jscript</instruction>
<instruction />
<instruction>function getLocal() {</instruction>
<instruction> var objWMIService = GetObject( "winmgmts://./root/CIMV2" );</instruction>
<instruction> var colItems = objWMIService.ExecQuery( "SELECT * FROM Win32_NetworkAdapterConfiguration WHERE MACAddress > '' AND IPEnabled = TRUE" );</instruction>
<instruction> var enumItems = new Enumerator(colItems);</instruction>
<instruction> var addresses = [];</instruction>
<instruction> for ( ; !enumItems.atEnd(); enumItems.moveNext())</instruction>
<instruction> addresses.push(enumItems.item().IPAddress.toArray()[0]);</instruction>
<instruction> return addresses.join(" ");</instruction>
<instruction>}</instruction>
<instruction />
<instruction>function setClipboard(txt) {</instruction>
<instruction> var wsh = new ActiveXObject("WScript.Shell");</instruction>
<instruction> cmd = "cmd.exe /c echo.|set /p =" + txt + "| clip" //this is a nolinefeed echo workaround</instruction>
<instruction> wsh.Run(cmd, 0, true);</instruction>
<instruction>}</instruction>
<instruction />
<instruction>setClipboard(getLocal());</instruction>
</function>
</button>
</button>