get public IP

Get help with using AutoHotkey and its commands and hotkeys
User avatar
jeeswg
Posts: 6904
Joined: 19 Dec 2016, 01:58
Location: UK

get public IP

26 Mar 2019, 18:00

Here's some code to get a computer's public IP. But it uses a specific website. Are there any other recommended websites, or is there a way to do this that doesn't involve using a website? Thanks.

Code: Select all

q:: ;get public IP
oWHR := ComObjCreate("WinHttp.WinHttpRequest.5.1")
oWHR.Open("GET", "http://www.netikus.net/show_ip.html")
oWHR.Send()
vIP := oWHR.ResponseText
oWHR := ""
MsgBox, % vIP
return

w:: ;get local IPs
vOutput := ""
Loop, 4
	vOutput .= A_IPAddress%A_Index% "`r`n"
MsgBox, % vOutput
vIP := A_IPAddress1
MsgBox, % vIP
return
See also:
recreate A_IPAddressXXX variables as a function - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=57112
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
Tigerlily
Posts: 283
Joined: 04 Oct 2018, 22:31

Re: get public IP

27 Mar 2019, 00:58

jeeswg wrote:
26 Mar 2019, 18:00
Here's some code to get a computer's public IP. But it uses a specific website. Are there any other recommended websites, or is there a way to do this that doesn't involve using a website? Thanks.

Code: Select all

q:: ;get public IP
oWHR := ComObjCreate("WinHttp.WinHttpRequest.5.1")
oWHR.Open("GET", "http://www.netikus.net/show_ip.html")
oWHR.Send()
vIP := oWHR.ResponseText
oWHR := ""
MsgBox, % vIP
return

w:: ;get local IPs
vOutput := ""
Loop, 4
	vOutput .= A_IPAddress%A_Index% "`r`n"
MsgBox, % vOutput
vIP := A_IPAddress1
MsgBox, % vIP
return
See also:
recreate A_IPAddressXXX variables as a function - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=57112
Maybe you could modify this code to use DNS Lookup to get the IP:

https://blog.protocolsyntax.com/2014/01/17/followup-dns-lookup-and-ping-in-excel/
-TL

Return to “Ask For Help”

Who is online

Users browsing this forum: BushMange, CEA6597, VACO BenQ, w0z and 195 guests