dexto Posted February 6, 2010 Share Posted February 6, 2010 (edited) Hello guys, Idea is to monitor UDP broadcast in the same subnet (private LAN) on port 67. In other words monitor DHCP requests. Here is the code that logically should work (moded UDPRecv example): ;;This is the UDP Server ;;Start this first ; Start The UDP Services ;============================================== UDPStartup() ; Bind to a SOCKET ;============================================== $socket = UDPBind("0.0.0.0", 67) If @error <> 0 Then ConsoleWrite(1) Exit EndIf While 1 ConsoleWrite(UDPRecv($socket, 255, 1)) WEnd Func OnAutoItExit() UDPCloseSocket($socket) UDPShutdown() EndFunc ;==>OnAutoItExit Packets are there, as confirmed by packet monitor (pic attached (first 3 packets)). What am I missing? Edited February 6, 2010 by dexto Link to comment Share on other sites More sharing options...
martin Posted February 6, 2010 Share Posted February 6, 2010 Hello guys, Idea is to monitor UDP broadcast in the same subnet (private LAN) on port 67. In other words monitor DHCP requests. Here is the code that logically should work (moded UDPRecv example): ;;This is the UDP Server ;;Start this first ; Start The UDP Services ;============================================== UDPStartup() ; Bind to a SOCKET ;============================================== $socket = UDPBind("0.0.0.0", 67) If @error <> 0 Then ConsoleWrite(1) Exit EndIf While 1 ConsoleWrite(UDPRecv($socket, 255, 1)) WEnd Func OnAutoItExit() UDPCloseSocket($socket) UDPShutdown() EndFunc ;==>OnAutoItExit Packets are there, as confirmed by packet monitor (pic attached (first 3 packets)). What am I missing? What version of AutoIt are you using? Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
dexto Posted February 6, 2010 Author Share Posted February 6, 2010 What version of AutoIt are you using?3.3.0.0I do not know if this anything to do with this but its worth mentioning that it is UDP broadcast send from unknown IP 0.0.0.0 and to broadcast IP 255.255.255.255 Link to comment Share on other sites More sharing options...
dexto Posted February 6, 2010 Author Share Posted February 6, 2010 Using 3.3.4.0 outcome is the same. Tried binding to adapter separately, using binary and auto mode - no difference. Link to comment Share on other sites More sharing options...
martin Posted February 6, 2010 Share Posted February 6, 2010 Using 3.3.4.0 outcome is the same.Tried binding to adapter separately, using binary and auto mode - no difference.Sorry, I see you're missing UDPOpen which will need the flag at 1. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
jchd Posted February 6, 2010 Share Posted February 6, 2010 It reminds me of a fix that had to do with UDP broadcast _sent_ to 255.255.255.255, but I may be off my head. No I still have a bit of brain: this was ticket #938, closed with version 3.3.1.1 so it's pretty old story. It may be related to your issue, or not at all. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
dexto Posted February 6, 2010 Author Share Posted February 6, 2010 Sorry, I see you're missing UDPOpen which will need the flag at 1. Like so? ; Start The UDP Services ;============================================== UDPStartup() ; Bind to a SOCKET ;============================================== #cs $socket = UDPBind("0.0.0.0", 67) If @error <> 0 Then ConsoleWrite(@error) Exit EndIf #ce $socket = UDPOpen("0.0.0.0", 67, 1) If @error <> 0 Then ConsoleWrite(@error) Exit EndIf While 1 $out = UDPRecv($socket, 255, 0) If $out <> "" Then ConsoleWrite($out & @CRLF) EndIf WEnd Func OnAutoItExit() UDPCloseSocket($socket) UDPShutdown() EndFunc ;==>OnAutoItExit I do not know if its right to use $socket from UDPOpen with UDPRecv but its acting the same. Link to comment Share on other sites More sharing options...
dexto Posted February 7, 2010 Author Share Posted February 7, 2010 Since I could not do it with UDPRecv here is the same using WinPcap:DHCP monitoring Link to comment Share on other sites More sharing options...
martin Posted February 7, 2010 Share Posted February 7, 2010 Ok, I'm paying proper attention now! I tried between 2 PCs like this: PC 1 had this code expandcollapse popup;;Start the other script first ; Start The UDP Services ;============================================== UDPStartup() ; Open a "SOCKET" ;============================================== $ThisPCIP = "192.168.1.104";running this script1 $socket2 = UDPBind($ThisPCIP, 65532) If @error <> 0 Then ConsoleWrite("error opening $socket2 , @error = " & @error & @CRLF) Exit EndIf $ThatPCIP = "255.255.255.255"; $socket = UDPOpen($ThatPCIP, 65532,1) If @error <> 0 Then ConsoleWrite("error opening $socket" & @CRLF) Exit EndIf $n=0 While 1 $data = UDPRecv($socket2, 50) If $data <> "" Then MsgBox(0, "UDP DATA", $data, 1) EndIf sleep(100) $n = $n + 1 $status = UDPSend($socket, "Message #" & $n) If $status = 0 then MsgBox(0, "ERROR", "Error while sending UDP message: " & @error) Exit EndIf WEnd Func OnAutoItExit() UDPCloseSocket($socket) UDPCloseSocket($socket2) UDPShutdown() EndFunc PC2 had this code which I started running first. ;Script2 ; Start The UDP Services ;============================================== UDPStartup() ; Bind to a SOCKET ;============================================== HotKeySet("{ESC}","xit") $ThisPCIP = "192.168.1.17";running script2 $socket = UDPBind($ThisPCIP, 65532) If @error <> 0 Then Exit While 1 $data = UDPRecv($socket, 50) If $data <> "" Then MsgBox(0, "UDP DATA", $data, 1) ;UDPSend($socket2,"Got number " & $data) EndIf sleep(100) WEnd Func OnAutoItExit() UDPCloseSocket($socket) UDPShutdown() EndFunc func xit() Exit EndFunc Both PCs received the messages as they should. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
dexto Posted February 7, 2010 Author Share Posted February 7, 2010 The only difference comes when computer that sends it and has no IP (Requesting DHCP services) (as in Source IP is 0.0.0.0 target IP is 255.255.255.255) its not showing anything. This might not be important at all because for the most part IP has to be present. In fact DHCP request is the only case where source computer broadcasting UDP from 0.0.0.0 IP. Link to comment Share on other sites More sharing options...
Ozgur Posted August 14, 2011 Share Posted August 14, 2011 Hi All,I hope it's not too frowned up on when old topics such as this are revived with answers months/years later. It's just that, people (like me) may end up hitting them through web-searches, and I though the following addition to this thread may be useful.The only difference comes when computer that sends it and has no IP (Requesting DHCP services) (as in Source IP is 0.0.0.0 target IP is 255.255.255.255) its not showing anything.This might not be important at all because for the most part IP has to be present. In fact DHCP request is the only case where source computer broadcasting UDP from 0.0.0.0 IP.Dexto,You may have figured this out long time ago, but in case you haven't; another difference is the packet size. DHCP packets have usually been >300 bytes in the networks I've monitored. When you put that 255 limit, UDPRecv() just ignores them. It doesn't do "partial" loads. You need to make sure that the "maxlen" parameter you use is bigger than your expected packet size. Ozgur Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now