Windows Port Knock Application
****The application now accepts DNS names and will correctly resolve them when knocking…rejoice!****
I’ve been getting a lot of false positives from virus scanners: IE Virustotal
This is a known issue with all autoit compiled scripts. They are NOT infected, it’s just that Autoit code has been picked up by virus scanners at one point, and now are forever flagged *sigh*. If you prefer, just simply compile the code below for yourself. If google sees me as having malicious code I may have to pull the compiled EXE and switch to just having the code(sorry about that).
It seems to be becoming more popular to use port knocking applications these days. Port knocking is sending connection attempts to a device in a specific pattern to unlock a specific service.
An example would be to send 3 UDP connection attempts to a Mikrotik router all on different port numbers in a specific order. It will then add your IP address to a specific address list so you can winbox in.
I found an application out there for windows that does it, but it only did UDP…I wanted one that would do both. I also wanted the ability to send text with the UDP connections to do L7 matches on it.
So, I wrote my own:
Basically what you do is fill out the entries, IP address, description and at least one knock port.
Fill out protocol type, the port you want to knock on and if it is UDP, you can optionally add some text to send with the message!
Here’s the program compiled and ready to go *password on zip is “portknock”*: PortKnock.zip (323376 downloads)
Here’s the code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 | #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_outfile=portknock.exe #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <ButtonConstants.au3> #include <ComboConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <GUIListBox.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <file.au3> #include <Array.au3> FileInstall("C:\Documents and Settings\greg\Desktop\autoit\portknock\TCP.exe", @ScriptDir & "\TCP.exe",0) ;knock it like it's hot $g_IP = "" $g_port = "" $ListLocation = 1 ;check config file if not FileExists(@ScriptDir & "\config.txt") Then ;create it with dummy info $file = FileOpen(@ScriptDir & "\config.txt", 1) If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf FileWriteLine($file, "Description;IPAddress;UDP;Port;GregRocks") FileClose($file) EndIf ReadConfig () ; Start The Services ;============================================== TCPStartUp() UDPStartup() ;########################################### #Region ### START Koda GUI section ### Form=C:\Documents and Settings\greg\Desktop\autoit\portknock\Form1.kxf $Form1_1 = GUICreate("GregSowell.com Port Knock", 441, 434, 192, 114) $List1 = GUICtrlCreateList("", 24, 16, 393, 201) $CBO1 = GUICtrlCreateCombo("None", 33, 280, 65, 25) GUICtrlSetData(-1, "TCP|UDP") $In1Port = GUICtrlCreateInput("", 121, 280, 105, 21) $In1Text = GUICtrlCreateInput("", 233, 280, 177, 21) $Label1 = GUICtrlCreateLabel("1", 9, 280, 10, 17) $BTNKnock = GUICtrlCreateButton("Knock", 96, 400, 73, 25, $WS_GROUP) $BTNAdd = GUICtrlCreateButton("Add/Update", 182, 400, 73, 25, $WS_GROUP) $BTNDelete = GUICtrlCreateButton("Delete", 272, 400, 73, 25, $WS_GROUP) $InIP = GUICtrlCreateInput("", 40, 234, 161, 21) $Label2 = GUICtrlCreateLabel("IP", 8, 234, 14, 17) $Label3 = GUICtrlCreateLabel("Type", 44, 259, 28, 17) $Label4 = GUICtrlCreateLabel("Port", 124, 259, 23, 17) $Label5 = GUICtrlCreateLabel("Text", 238, 259, 25, 17) $CBO2 = GUICtrlCreateCombo("None", 33, 309, 65, 25) GUICtrlSetData(-1, "TCP|UDP") $In2Port = GUICtrlCreateInput("", 121, 309, 105, 21) $In2Text = GUICtrlCreateInput("", 233, 309, 177, 21) $Label6 = GUICtrlCreateLabel("2", 9, 309, 10, 17) $CBO3 = GUICtrlCreateCombo("None", 33, 341, 65, 25) GUICtrlSetData(-1, "TCP|UDP") $In3Port = GUICtrlCreateInput("", 121, 341, 105, 21) $In3Text = GUICtrlCreateInput("", 233, 341, 177, 21) $Label7 = GUICtrlCreateLabel("3", 9, 341, 10, 17) $CBO4 = GUICtrlCreateCombo("None", 33, 367, 65, 25) GUICtrlSetData(-1, "TCP|UDP") $In4Port = GUICtrlCreateInput("", 121, 367, 105, 21) $In4Text = GUICtrlCreateInput("", 233, 367, 177, 21) $Label8 = GUICtrlCreateLabel("4", 9, 367, 10, 17) $InDesc = GUICtrlCreateInput("", 253, 234, 161, 21) $Label9 = GUICtrlCreateLabel("Desc", 221, 234, 29, 17) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### PopList() While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $BTNAdd ; $foundOne = 0 for $y = 1 to $aConfig ;loop through until we find the correct line if StringLeft($aConfig[$y], StringInStr($aConfig[$y], ";") - 1) == GUICtrlRead($InDesc) Then ; we have our match, update $foundOne = $y EndIf Next if $foundOne == 0 Then ;we didn't find a match above, so write it to file, then reload listbox $tempNewEntry = GUICtrlRead($InDesc) & ";" & GUICtrlRead($InIP) & ";" & GUICtrlRead($CBO1) & ";" & GUICtrlRead($In1Port) & ";" & GUICtrlRead($In1Text) if GUICtrlRead($CBO2) <> "None" Then ;add 2 $tempNewEntry = $tempNewEntry & ";" & GUICtrlRead($CBO2) & ";" & GUICtrlRead($In2Port) & ";" & GUICtrlRead($In2Text) if GUICtrlRead($CBO3) <> "None" Then ;add 3 $tempNewEntry = $tempNewEntry & ";" & GUICtrlRead($CBO3) & ";" & GUICtrlRead($In3Port) & ";" & GUICtrlRead($In3Text) if GUICtrlRead($CBO4) <> "None" Then ;add 4 $tempNewEntry = $tempNewEntry & ";" & GUICtrlRead($CBO4) & ";" & GUICtrlRead($In4Port) & ";" & GUICtrlRead($In4Text) EndIf EndIf EndIf _ArrayAdd($aConfig, $tempNewEntry) Else ;does exist, and write over line $y $aConfig[$foundOne] = GUICtrlRead($InDesc) & ";" & GUICtrlRead($InIP) & ";" & GUICtrlRead($CBO1) & ";" & GUICtrlRead($In1Port) & ";" & GUICtrlRead($In1Text) if GUICtrlRead($CBO2) <> "None" Then ;add 2 $aConfig[$foundOne] = $aConfig[$foundOne] & ";" & GUICtrlRead($CBO2) & ";" & GUICtrlRead($In2Port) & ";" & GUICtrlRead($In2Text) if GUICtrlRead($CBO3) <> "None" Then ;add 3 $aConfig[$foundOne] = $aConfig[$foundOne] & ";" & GUICtrlRead($CBO3) & ";" & GUICtrlRead($In3Port) & ";" & GUICtrlRead($In3Text) if GUICtrlRead($CBO4) <> "None" Then ;add 4 $aConfig[$foundOne] = $aConfig[$foundOne] & ";" & GUICtrlRead($CBO4) & ";" & GUICtrlRead($In4Port) & ";" & GUICtrlRead($In4Text) EndIf EndIf EndIf EndIf ;write array to file _FileWriteFromArray(@ScriptDir & "\config.txt", $aConfig,1) ReadConfig() PopList() Case $BTNDelete ; for $y = 1 to $aConfig[0] ;loop through until we find the correct line if StringLeft($aConfig[$y], StringInStr($aConfig[$y], ";") - 1) == GUICtrlRead($InDesc) Then ; we have our match, update _ArrayDelete($aConfig, $y) _FileWriteFromArray(@ScriptDir & "\config.txt", $aConfig,1) ReadConfig() PopList() EndIf Next Case $BTNKnock ; $g_IP = GUICtrlRead($InIP) $g_port = GUICtrlRead($In1Port) $g_text = "" $g_text = GUICtrlRead($In1Text) if GUICtrlRead($CBO1) == "TCP" Then TCPKnock() Else UDPKnock() EndIf sleep(300) if GUICtrlRead($CBO2) <> "None" Then $g_port = GUICtrlRead($In2Port) $g_text = "" $g_text = GUICtrlRead($In2Text) EndIf if GUICtrlRead($CBO2) == "TCP" Then TCPKnock() Elseif GUICtrlRead($CBO2) == "UDP" Then UDPKnock() EndIf sleep(300) if GUICtrlRead($CBO3) <> "None" Then $g_port = GUICtrlRead($In3Port) $g_text = "" $g_text = GUICtrlRead($In3Text) EndIf if GUICtrlRead($CBO3) == "TCP" Then TCPKnock() Elseif GUICtrlRead($CBO3) == "UDP" Then UDPKnock() EndIf sleep(300) if GUICtrlRead($CBO4) <> "None" Then $g_port = GUICtrlRead($In4Port) $g_text = "" $g_text = GUICtrlRead($In4Text) EndIf if GUICtrlRead($CBO4) == "TCP" Then TCPKnock() Elseif GUICtrlRead($CBO4) == "UDP" Then UDPKnock() EndIf ToolTip("knock complete") sleep(5000) ToolTip("") case $GUI_EVENT_PRIMARYUP ;mouse was pressed, lets check to see if they choose a new item in list ;check which list item is highlighted $tempList = GUICtrlRead($List1) ;see if this is new item chosen or just a click somewhere on the prog if $tempList <> $ListLocation and $tempList <> "" Then ;change, update everything ;set list location to the temp value $ListLocation = $tempList ;clear the entries GUICtrlSetData($InDesc,"") GUICtrlSetData($InIP,"") GUICtrlSetData($CBO1,"None") GUICtrlSetData($In1Port,"") GUICtrlSetData($In1Text,"") GUICtrlSetData($CBO2,"None") GUICtrlSetData($In2Port,"") GUICtrlSetData($In2Text,"") GUICtrlSetData($CBO3,"None") GUICtrlSetData($In3Port,"") GUICtrlSetData($In3Text,"") GUICtrlSetData($CBO4,"None") GUICtrlSetData($In4Port,"") GUICtrlSetData($In4Text,"") ;set the entries for $y = 1 to $aConfig[0] ;loop through until we find the correct line if StringLeft($aConfig[$y], StringInStr($aConfig[$y], ";") - 1) == $ListLocation Then ; we have our match $ConfigLine = $aConfig[$y] EndIf Next ;fill in all the boxes GUICtrlSetData($InDesc, $ListLocation) GUICtrlSetData($InIP, StringMid($ConfigLine,StringInStr($ConfigLine,";") + 1, StringInStr($ConfigLine,";",0,2) - StringInStr($ConfigLine,";") - 1)) GUICtrlSetData($CBO1, StringMid($ConfigLine,StringInStr($ConfigLine,";",0,2) + 1, StringInStr($ConfigLine,";",0,3) - StringInStr($ConfigLine,";",0,2) - 1)) GUICtrlSetData($In1Port, StringMid($ConfigLine,StringInStr($ConfigLine,";",0,3) + 1, StringInStr($ConfigLine,";",0,4) - StringInStr($ConfigLine,";",0,3) - 1)) GUICtrlSetData($In1Text, StringMid($ConfigLine,StringInStr($ConfigLine,";",0,4) + 1, StringInStr($ConfigLine,";",0,5) - StringInStr($ConfigLine,";",0,4) - 1)) $tempstring = StringReplace($ConfigLine, ";", ";") $tempCount = @extended if $tempCount > 4 Then ;we have a second set GUICtrlSetData($CBO2, StringMid($ConfigLine,StringInStr($ConfigLine,";",0,5) + 1, StringInStr($ConfigLine,";",0,6) - StringInStr($ConfigLine,";",0,5) - 1)) GUICtrlSetData($In2Port, StringMid($ConfigLine,StringInStr($ConfigLine,";",0,6) + 1, StringInStr($ConfigLine,";",0,7) - StringInStr($ConfigLine,";",0,6) - 1)) GUICtrlSetData($In2Text, StringMid($ConfigLine,StringInStr($ConfigLine,";",0,7) + 1, StringInStr($ConfigLine,";",0,8) - StringInStr($ConfigLine,";",0,7) - 1)) EndIf if $tempCount > 7 Then ;we have a third set GUICtrlSetData($CBO3, StringMid($ConfigLine,StringInStr($ConfigLine,";",0,8) + 1, StringInStr($ConfigLine,";",0,9) - StringInStr($ConfigLine,";",0,8) - 1)) GUICtrlSetData($In3Port, StringMid($ConfigLine,StringInStr($ConfigLine,";",0,9) + 1, StringInStr($ConfigLine,";",0,10) - StringInStr($ConfigLine,";",0,9) - 1)) GUICtrlSetData($In3Text, StringMid($ConfigLine,StringInStr($ConfigLine,";",0,10) + 1, StringInStr($ConfigLine,";",0,11) - StringInStr($ConfigLine,";",0,10) - 1)) EndIf if $tempCount > 10 Then ;we have a fourth set GUICtrlSetData($CBO4, StringMid($ConfigLine,StringInStr($ConfigLine,";",0,11) + 1, StringInStr($ConfigLine,";",0,12) - StringInStr($ConfigLine,";",0,11) - 1)) GUICtrlSetData($In4Port, StringMid($ConfigLine,StringInStr($ConfigLine,";",0,12) + 1, StringInStr($ConfigLine,";",0,13) - StringInStr($ConfigLine,";",0,12) - 1)) GUICtrlSetData($In4Text, StringMid($ConfigLine,StringInStr($ConfigLine,";",0,4) + 1)) EndIf EndIf Case $GUI_EVENT_CLOSE TCPShutdown() UDPShutdown() Exit EndSwitch WEnd ;########################################### Func PopList () ;populate list box GUICtrlSetData($List1, "") for $x = 1 to $aConfig[0] GUICtrlSetData($List1, StringLeft($aConfig[$x], StringInStr($aConfig[$x], ";") - 1)) Next EndFunc Func ReadConfig () Global $aConfig If Not _FileReadToArray(@ScriptDir & "\config.txt",$aConfig) Then MsgBox(4096,"Error", " Error reading log to Array error:" & @error) Exit EndIf EndFunc ;knock functions Func TCPKnock () ToolTip("knocking " & $g_IP & " " & $g_port) run("""" & @ScriptDir & "\TCP.exe"" " & $g_IP & " " & $g_port) ToolTip("") EndFunc Func UDPKnock () ToolTip("knocking " & $g_IP & " " & $g_port) $socket = UDPOpen($g_IP, $g_port) $status = UDPSend($socket, $g_text) UDPCloseSocket($socket) ToolTip("") EndFunc |
TCP.exe code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | #NoTrayIcon ;include <GUIConstantsEx.au3> Opt('MustDeclareVars', 1) ; Set Some reusable info ;-------------------------- Local $ConnectedSocket, $szData ; Set $szIPADDRESS to wherever the SERVER is. We will change a PC name into an IP Address ; Local $szServerPC = @ComputerName ; Local $szIPADDRESS = TCPNameToIP($szServerPC) Local $szIPADDRESS = $CmdLine[1] Local $nPORT = $CmdLine[2] ; Start The TCP Services ;============================================== TCPStartup() ; Initialize a variable to represent a connection ;============================================== $ConnectedSocket = -1 ;Attempt to connect to SERVER at its IP and PORT 33891 ;======================================================= $ConnectedSocket = TCPConnect($szIPADDRESS, $nPORT) TCPCloseSocket($ConnectedSocket) |
Be sure to check out Jimmys lil write up on UDP port knocking with text 🙂
BTW, I just threw this together and haven’t properly tested, so let me know how it goes 😛
Hello Greg,
I have been setting up port knocking on my Mikrotik router. My setup is such that the knocks strictly have to be received by the router from the source IP in the correct order, with no other packets on different ports in between. I tried to use your app to send two TCP knocks followed by two UDP knocks, and it turns out that udp knock #3 was systematically reaching the firewall before TCP knock #2 (the test was on my lan, not from the internet). When I switched to 4 TCP knocks instead, all was well.
I realize that this may be due to the nature of network comms or TCP/UDP stacks, but I would maybe suggest that your program allow to introduce some custom delay between the knocks to prevent this problem.
All the best, feel free to email me if you need more details.
David
… I see in the code that you have hardcoded delays of 300ms between the knocks. It seems that I have the problem only when mixing tcp and udp knocks. If they are all tcp or all udp, all is well. I’ll try to recompile your code with bigger delays.
@David
Thanks for the update. If upping the delays fixes your issues, let me know and I’ll up them here. I’ve yet to have issues thus far personally, but every machine is different.
I could possibly add some custom delay fields, but I’m currently so busy that I don’t have time to adjust the program. Possibly in a couple of weeks…
Thanks a lot for this program, it does exactly what I expected for 🙂
Greg, I have used port knocking for some time, and just ran across your clever tool. I like the interface and the recording of multiple knock targets, each with unique settings.
However, I almost always use URL addresses for remote routers, hosted at DynDns, mostly. It would be great if your tool could store URLs when new entries are added, the then resolve them when executed, and use the result as the IP address.
Ever give any thought to that?
Thanks,
@Mike
It didn’t even occur to me in the beginning, but it sure makes sense. BTW, I assume you tested it unsuccessfully with a URL? If it doesn’t already, it wouldn’t take much to make the adjustment.
Have made some modification: add DNS support(Not fully tested) and remove some error codes(when delete)
Code/
#cs —————————————————————————-
AutoIt Version: 3.3.10.2
Author: myName
Script Function:
Template AutoIt script.
#ce —————————————————————————-
; Script Start – Add your code below here
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_outfile=portknock.exe
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
FileInstall(“C:\Users\raffaello\Dropbox\Pojeto_Autoit\Portknock\TCP.exe”, @ScriptDir & “\TCP.exe”, 0)
;knock it like it’s hot
$g_IP = “”
$g_port = “”
$ListLocation = 1
Global $aConfig
;check config file
If Not FileExists(@ScriptDir & “\config.txt”) Then
;create it with dummy info
$file = FileOpen(@ScriptDir & “\config.txt”, 1)
If $file = -1 Then
MsgBox(0, “Error”, “Unable to open file.”)
Exit
EndIf
FileWriteLine($file, “Description;IPAddress;UDP;Port;GregRocks”)
FileClose($file)
EndIf
ReadConfig()
; Start The Services
;==============================================
TCPStartup()
UDPStartup()
;###########################################
#Region ### START Koda GUI section ### Form=C:\Documents and Settings\greg\Desktop\autoit\portknock\Form1.kxf
$Form1_1 = GUICreate(“GregSowell.com Port Knock”, 441, 434, 192, 114)
$List1 = GUICtrlCreateList(“”, 24, 16, 393, 201)
$CBO1 = GUICtrlCreateCombo(“None”, 33, 280, 65, 25)
GUICtrlSetData(-1, “TCP|UDP”)
$In1Port = GUICtrlCreateInput(“”, 121, 280, 105, 21)
$In1Text = GUICtrlCreateInput(“”, 233, 280, 177, 21)
$Label1 = GUICtrlCreateLabel(“1”, 9, 280, 10, 17)
$BTNKnock = GUICtrlCreateButton(“Knock”, 96, 400, 73, 25, $WS_GROUP)
$BTNAdd = GUICtrlCreateButton(“Add/Update”, 182, 400, 73, 25, $WS_GROUP)
$BTNDelete = GUICtrlCreateButton(“Delete”, 272, 400, 73, 25, $WS_GROUP)
$InIP = GUICtrlCreateInput(“”, 40, 234, 161, 21)
$Label2 = GUICtrlCreateLabel(“IP”, 8, 234, 14, 17)
$Label3 = GUICtrlCreateLabel(“Type”, 44, 259, 28, 17)
$Label4 = GUICtrlCreateLabel(“Port”, 124, 259, 23, 17)
$Label5 = GUICtrlCreateLabel(“Text”, 238, 259, 25, 17)
$CBO2 = GUICtrlCreateCombo(“None”, 33, 309, 65, 25)
GUICtrlSetData(-1, “TCP|UDP”)
$In2Port = GUICtrlCreateInput(“”, 121, 309, 105, 21)
$In2Text = GUICtrlCreateInput(“”, 233, 309, 177, 21)
$Label6 = GUICtrlCreateLabel(“2”, 9, 309, 10, 17)
$CBO3 = GUICtrlCreateCombo(“None”, 33, 341, 65, 25)
GUICtrlSetData(-1, “TCP|UDP”)
$In3Port = GUICtrlCreateInput(“”, 121, 341, 105, 21)
$In3Text = GUICtrlCreateInput(“”, 233, 341, 177, 21)
$Label7 = GUICtrlCreateLabel(“3”, 9, 341, 10, 17)
$CBO4 = GUICtrlCreateCombo(“None”, 33, 367, 65, 25)
GUICtrlSetData(-1, “TCP|UDP”)
$In4Port = GUICtrlCreateInput(“”, 121, 367, 105, 21)
$In4Text = GUICtrlCreateInput(“”, 233, 367, 177, 21)
$Label8 = GUICtrlCreateLabel(“4”, 9, 367, 10, 17)
$InDesc = GUICtrlCreateInput(“”, 253, 234, 161, 21)
$Label9 = GUICtrlCreateLabel(“Desc”, 221, 234, 29, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
PopList()
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $BTNAdd
;
$foundOne = 0
For $y = 1 To $aConfig[0]
;loop through until we find the correct line
If StringLeft($aConfig[$y], StringInStr($aConfig[$y], “;”) – 1) == GUICtrlRead($InDesc) Then
; we have our match, update
$foundOne = $y
EndIf
;~ ExitLoop
Next
If $foundOne == 0 Then
;we didn’t find a match above, so write it to file, then reload listbox
$tempNewEntry = GUICtrlRead($InDesc) & “;” & GUICtrlRead($InIP) & “;” & GUICtrlRead($CBO1) & “;” & GUICtrlRead($In1Port) & “;” & GUICtrlRead($In1Text)
If GUICtrlRead($CBO2) “None” Then
;add 2
$tempNewEntry = $tempNewEntry & “;” & GUICtrlRead($CBO2) & “;” & GUICtrlRead($In2Port) & “;” & GUICtrlRead($In2Text)
If GUICtrlRead($CBO3) “None” Then
;add 3
$tempNewEntry = $tempNewEntry & “;” & GUICtrlRead($CBO3) & “;” & GUICtrlRead($In3Port) & “;” & GUICtrlRead($In3Text)
If GUICtrlRead($CBO4) “None” Then
;add 4
$tempNewEntry = $tempNewEntry & “;” & GUICtrlRead($CBO4) & “;” & GUICtrlRead($In4Port) & “;” & GUICtrlRead($In4Text)
EndIf
EndIf
EndIf
_ArrayAdd($aConfig, $tempNewEntry)
Else
;does exist, and write over line $y
$aConfig[$foundOne] = GUICtrlRead($InDesc) & “;” & GUICtrlRead($InIP) & “;” & GUICtrlRead($CBO1) & “;” & GUICtrlRead($In1Port) & “;” & GUICtrlRead($In1Text)
If GUICtrlRead($CBO2) “None” Then
;add 2
$aConfig[$foundOne] = $aConfig[$foundOne] & “;” & GUICtrlRead($CBO2) & “;” & GUICtrlRead($In2Port) & “;” & GUICtrlRead($In2Text)
If GUICtrlRead($CBO3) “None” Then
;add 3
$aConfig[$foundOne] = $aConfig[$foundOne] & “;” & GUICtrlRead($CBO3) & “;” & GUICtrlRead($In3Port) & “;” & GUICtrlRead($In3Text)
If GUICtrlRead($CBO4) “None” Then
;add 4
$aConfig[$foundOne] = $aConfig[$foundOne] & “;” & GUICtrlRead($CBO4) & “;” & GUICtrlRead($In4Port) & “;” & GUICtrlRead($In4Text)
EndIf
EndIf
EndIf
EndIf
;write array to file
_FileWriteFromArray(@ScriptDir & “\config.txt”, $aConfig, 1)
ReadConfig()
PopList()
Case $BTNDelete
;
ConsoleWrite(” 3> ” & $aConfig[0] & @CRLF)
For $y = 1 To UBound($aConfig)
ConsoleWrite(” 4> ” & $aConfig[0] & @CRLF)
ConsoleWrite(” info POS >” & $y & ” INFO >” & $aConfig[$y] & @CRLF)
;loop through until we find the correct line
If StringLeft($aConfig[$y], StringInStr($aConfig[$y], “;”) – 1) == GUICtrlRead($InDesc) Then
; we have our match, update
_ArrayDelete($aConfig, $y)
_FileWriteFromArray(@ScriptDir & “\config.txt”, $aConfig, 1)
ConsoleWrite(” 5> ” & $aConfig[0] & @CRLF)
ReadConfig()
PopList()
ExitLoop
EndIf
ConsoleWrite(” 6> ” & $aConfig[0] & @CRLF)
Next
Case $BTNKnock
;
$g_IP = GUICtrlRead($InIP)
$g_port = GUICtrlRead($In1Port)
$g_text = “”
$g_text = GUICtrlRead($In1Text)
If GUICtrlRead($CBO1) == “TCP” Then
TCPKnock()
Else
UDPKnock()
EndIf
Sleep(300)
If GUICtrlRead($CBO2) “None” Then
$g_port = GUICtrlRead($In2Port)
$g_text = “”
$g_text = GUICtrlRead($In2Text)
EndIf
If GUICtrlRead($CBO2) == “TCP” Then
TCPKnock()
ElseIf GUICtrlRead($CBO2) == “UDP” Then
UDPKnock()
EndIf
Sleep(300)
If GUICtrlRead($CBO3) “None” Then
$g_port = GUICtrlRead($In3Port)
$g_text = “”
$g_text = GUICtrlRead($In3Text)
EndIf
If GUICtrlRead($CBO3) == “TCP” Then
TCPKnock()
ElseIf GUICtrlRead($CBO3) == “UDP” Then
UDPKnock()
EndIf
Sleep(300)
If GUICtrlRead($CBO4) “None” Then
$g_port = GUICtrlRead($In4Port)
$g_text = “”
$g_text = GUICtrlRead($In4Text)
EndIf
If GUICtrlRead($CBO4) == “TCP” Then
TCPKnock()
ElseIf GUICtrlRead($CBO4) == “UDP” Then
UDPKnock()
EndIf
ToolTip(“knock complete”)
Sleep(5000)
ToolTip(“”)
Case $GUI_EVENT_PRIMARYUP
;mouse was pressed, lets check to see if they choose a new item in list
;check which list item is highlighted
$tempList = GUICtrlRead($List1)
;see if this is new item chosen or just a click somewhere on the prog
If $tempList $ListLocation And $tempList “” Then
;change, update everything
;set list location to the temp value
$ListLocation = $tempList
;clear the entries
GUICtrlSetData($InDesc, “”)
GUICtrlSetData($InIP, “”)
GUICtrlSetData($CBO1, “None”)
GUICtrlSetData($In1Port, “”)
GUICtrlSetData($In1Text, “”)
GUICtrlSetData($CBO2, “None”)
GUICtrlSetData($In2Port, “”)
GUICtrlSetData($In2Text, “”)
GUICtrlSetData($CBO3, “None”)
GUICtrlSetData($In3Port, “”)
GUICtrlSetData($In3Text, “”)
GUICtrlSetData($CBO4, “None”)
GUICtrlSetData($In4Port, “”)
GUICtrlSetData($In4Text, “”)
;set the entries
For $y = 1 To $aConfig[0]
;loop through until we find the correct line
If StringLeft($aConfig[$y], StringInStr($aConfig[$y], “;”) – 1) == $ListLocation Then
; we have our match
$ConfigLine = $aConfig[$y]
EndIf
Next
;fill in all the boxes
GUICtrlSetData($InDesc, $ListLocation)
GUICtrlSetData($InIP, StringMid($ConfigLine, StringInStr($ConfigLine, “;”) + 1, StringInStr($ConfigLine, “;”, 0, 2) – StringInStr($ConfigLine, “;”) – 1))
GUICtrlSetData($CBO1, StringMid($ConfigLine, StringInStr($ConfigLine, “;”, 0, 2) + 1, StringInStr($ConfigLine, “;”, 0, 3) – StringInStr($ConfigLine, “;”, 0, 2) – 1))
GUICtrlSetData($In1Port, StringMid($ConfigLine, StringInStr($ConfigLine, “;”, 0, 3) + 1, StringInStr($ConfigLine, “;”, 0, 4) – StringInStr($ConfigLine, “;”, 0, 3) – 1))
GUICtrlSetData($In1Text, StringMid($ConfigLine, StringInStr($ConfigLine, “;”, 0, 4) + 1, StringInStr($ConfigLine, “;”, 0, 5) – StringInStr($ConfigLine, “;”, 0, 4) – 1))
$tempstring = StringReplace($ConfigLine, “;”, “;”)
$tempCount = @extended
If $tempCount > 4 Then
;we have a second set
GUICtrlSetData($CBO2, StringMid($ConfigLine, StringInStr($ConfigLine, “;”, 0, 5) + 1, StringInStr($ConfigLine, “;”, 0, 6) – StringInStr($ConfigLine, “;”, 0, 5) – 1))
GUICtrlSetData($In2Port, StringMid($ConfigLine, StringInStr($ConfigLine, “;”, 0, 6) + 1, StringInStr($ConfigLine, “;”, 0, 7) – StringInStr($ConfigLine, “;”, 0, 6) – 1))
GUICtrlSetData($In2Text, StringMid($ConfigLine, StringInStr($ConfigLine, “;”, 0, 7) + 1, StringInStr($ConfigLine, “;”, 0, 8) – StringInStr($ConfigLine, “;”, 0, 7) – 1))
EndIf
If $tempCount > 7 Then
;we have a third set
GUICtrlSetData($CBO3, StringMid($ConfigLine, StringInStr($ConfigLine, “;”, 0, 8) + 1, StringInStr($ConfigLine, “;”, 0, 9) – StringInStr($ConfigLine, “;”, 0, 8) – 1))
GUICtrlSetData($In3Port, StringMid($ConfigLine, StringInStr($ConfigLine, “;”, 0, 9) + 1, StringInStr($ConfigLine, “;”, 0, 10) – StringInStr($ConfigLine, “;”, 0, 9) – 1))
GUICtrlSetData($In3Text, StringMid($ConfigLine, StringInStr($ConfigLine, “;”, 0, 10) + 1, StringInStr($ConfigLine, “;”, 0, 11) – StringInStr($ConfigLine, “;”, 0, 10) – 1))
EndIf
If $tempCount > 10 Then
;we have a fourth set
GUICtrlSetData($CBO4, StringMid($ConfigLine, StringInStr($ConfigLine, “;”, 0, 11) + 1, StringInStr($ConfigLine, “;”, 0, 12) – StringInStr($ConfigLine, “;”, 0, 11) – 1))
GUICtrlSetData($In4Port, StringMid($ConfigLine, StringInStr($ConfigLine, “;”, 0, 12) + 1, StringInStr($ConfigLine, “;”, 0, 13) – StringInStr($ConfigLine, “;”, 0, 12) – 1))
GUICtrlSetData($In4Text, StringMid($ConfigLine, StringInStr($ConfigLine, “;”, 0, 13) + 1))
EndIf
EndIf
Case $GUI_EVENT_CLOSE
TCPShutdown()
UDPShutdown()
Exit
EndSwitch
WEnd
;###########################################
Func PopList()
;populate list box
GUICtrlSetData($List1, “”)
For $x = 1 To $aConfig[0]
GUICtrlSetData($List1, StringLeft($aConfig[$x], StringInStr($aConfig[$x], “;”) – 1))
Next
EndFunc ;==>PopList
Func ReadConfig()
;~ MsgBox(4096,”Error”, ” Error reading log to Array error:” & @error)
Global $aConfig
If Not _FileReadToArray(@ScriptDir & “\config.txt”, $aConfig, 1) Then
MsgBox(4096, “Error”, ” Error reading log to Array error:” & @error)
Exit
EndIf
;~ Global $aConfig
ConsoleWrite(” > ” & $aConfig & @CRLF)
ConsoleWrite(” 2> ” & $aConfig[0] & @CRLF)
EndFunc ;==>ReadConfig
;knock functions
Func TCPKnock()
$g_IP = _ChkDNS()
ToolTip(“knocking ” & $g_IP & ” ” & $g_port)
Run(“””” & @ScriptDir & “\TCP.exe”” ” & $g_IP & ” ” & $g_port)
ToolTip(“”)
EndFunc ;==>TCPKnock
Func UDPKnock()
$g_IP = _ChkDNS()
ToolTip(“knocking ” & $g_IP & ” ” & $g_port)
$socket = UDPOpen($g_IP, $g_port)
$status = UDPSend($socket, $g_text)
UDPCloseSocket($socket)
ToolTip(“”)
EndFunc ;==>UDPKnock
Func _ChkDNS()
ConsoleWrite(“Test >”&$g_IP &@CR)
TCPStartup()
; Assign a Local variable the IP address of http://www.autoitscript.com.
$g_IP = TCPNameToIP($g_IP)
; If an error occurred display the error code and return False.
If @error 0 Then
MsgBox($MB_SYSTEMMODAL, “”, “Error code: ” & @error)
;~ Return False
Else
; Display the IP address.
;~ MsgBox($MB_SYSTEMMODAL, “”, “Domain name to IP :” & $g_IP)
;~ ConsoleWrite(“Teste >”&$g_IP &@CR)
Return $g_IP
EndIf
TCPShutdown()
EndFunc ;==>_ChkDNS
/Code
The include is not showing, but only need to add this new one here
“”#include “”
@Raffav
Thanks for the update sir!
Can someone make the version that does name resolution available at the download link? The one that’s there just silently fails if you provide it anything but a numeric IP address, which set me back some server-side debugging time. Thanks.
Wait no longer @CD; I’ve added DNS resolution! It honestly only took two additional lines of code…only took me like 7 years to update it 😉