Ping4 - Question
Ping4 - Question
Can this script be used to check if a TCP port is open?
Re: Ping4 - IPv4 ping function (2015-07-16)
No, but I just created a function for you -> GetTcpPortTable.ahk (GitHub)
Ref:
- GetTcpTable function (msdn)
- MIB_TCPTABLE structure (msdn)
- MIB_TCPROW structure (msdn)
Ref:
- GetTcpTable function (msdn)
- MIB_TCPTABLE structure (msdn)
- MIB_TCPROW structure (msdn)
[AHK] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile
Re: Ping4 - IPv4 ping function (2015-07-16)
jNizM: That's great. Thank you. But, how can I pass a remote IP/Host:Port to this and verify if it is open?
Re: Ping4 - IPv4 ping function (2015-07-16)
Will modify the function to get LocalIP, LocalPort, RemoteIP, RemotePort & Status
[AHK] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile
Re: Ping4 - IPv4 ping function (2015-07-16)
Thank you. That would be very useful
Re: Ping4 - IPv4 ping function (2015-07-16)
Here you go -> GetTcpTable.ahk (GitHub)
[AHK] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile
Re: Ping4 - IPv4 ping function (2015-07-16)
jNizM: I just want to check if a remote TCP port is open. Here's my current (crappy) script:
Code: Select all
CheckPort(Host,Port)
{
; DllCall("AllocConsole")
; WinHide % "ahk_id " DllCall("GetConsoleWindow", "ptr")
Loop, Parse, % ComObjCreate("WScript.Shell").Exec("Addons\Software\SysinternalsSuite\psping.exe -i 0 -n 0 " Host ":" Port).StdOut.ReadAll(),"`n"
{
if (A_Index = 3)
{
if InStr(A_LoopField,"ms")
Return 1
else
Return 0
}
}
}
Re: Ping4 - IPv4 ping function (2015-07-16)
Code: Select all
RemoteIP := "192.168.0.1"
RemotePort := "445"
for i, v in GetTcpTable()
if (RemoteIP = v.RemoteIP) && (RemotePort = v.RemotePort)
MsgBox % v.State
[AHK] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile
Re: Ping4 - IPv4 ping function (2015-07-16)
Thanks, but this port is open and does not return anything
Code: Select all
RemoteIP := "10.211.114.9"
RemotePort := 6100
for i, v in GetTcpTable()
{
if (RemoteIP = v.RemoteIP) && (RemotePort = v.RemotePort)
MsgBox % v.State
}
Re: Ping4 - IPv4 ping function (2015-07-16)
Not sure if there was a misunderstanding here
Re: Ping4 - Question
Can you look into this? It retrieves the IPv4 TCP connection table.
I can add IPv6 too if needed...
Code: Select all
Gui, Margin, 5, 5
Gui, Add, ListView, xm ym w600 h600, % "LocalIP|LocalPort|RemoteIP|RemotePort|State"
for i, v in GetTcpTable()
LV_Add("", v.LocalIP, v.LocalPort, v.RemoteIP, v.RemotePort, v.State)
LV_ModifyCol(1, 110), LV_ModifyCol(2, 75), LV_ModifyCol(3, 110), LV_ModifyCol(4, 75), LV_ModifyCol(5, 100)
Gui, Show, AutoSize
return
GuiEscape:
GuiClose:
ExitApp
[AHK] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile
Re: Ping4 - Question
jNizM: I'm not trying to list local ports that are open. I am trying to 'ping' a remote IP with Port to verify if it is open. Kind of like 'telnet IP PORT' in cmd. This way I can see if a remote machine is running a certain program.
Re: Ping4 - Question
You cannot ping a port.
What you can do is try to open a socket on the remote port. If the connection works, the port is open.
Socket Class
What you can do is try to open a socket on the remote port. If the connection works, the port is open.
Socket Class
[AHK] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile
Who is online
Users browsing this forum: mebelantikjaya and 288 guests