Jump to content

broadcast to 255.255.255.255 doesn't work


Recommended Posts

hello,

I have a router in my network. To enter the special admin mode, it is necessary to send a broadcast within the first 3 seconds of the boot-phase of the device.

If the device receives the broadcast, it stops the normal boot and I can make a ftp-connection to the device. The broadcast must be send on port 5035 to address 255.255.255.255.

My script works without error, but the device doesn't stops. If i use wireshark, I see nothing. No broadcast, no traffic on port 5035. :-(

If I use the calculated broadcast-address of my LAN (192.168.178.255), I see the traffic with wireshark, but the device doesn't stops the boot. :-(

If I use a perl script with the same functionality (broadcast to 255.255.255.255), the device stops! If I compare the whireshark-snaps of the perl-broadcast with 255.255.255.255

and my script with the working broadcast to 192.168.178.255, I see a major difference is the destination-address on the IP-Layer. the perl-script sends to 255.255.255.255 in

then ethernet-frame and ip-frame! the destination-address of the broadcast must be 255.255.255.255.

why I can't send udp-packets to address 255.255.255.255? is my script wrong? or is this a bug? if yes, is there any workaround? it doesn't help the send the broadcast to the "LAN"-broadcast.

Many thanks in advance!

R@iner

; attention: debug-output only with ConsoleWrite!

Opt("MustDeclareVars", 1)

; --- Define vars ---
Global $ReceiveSocket, $SendSocket, $ReceivedData, $Counter, $SendStatus
Global $MaxTries = 20; for the main-loop
Global $MyIPaddress = "192.168.178.20"; equal to @IPAddress1
Global $Port = "5035"
Global $BroadcastAdr = "255.255.255.255"
; Global $BroadcastAdr = "192.168.178.255"; Sending and receiving works (netmask = 255.255.255.0)
Global $SendingData = "Hello"; only for test, if the broadcast to 255.255.255.255 works, here must be the stop-sequence. see perl-script

; --- Start UDP ---
UDPStartup()
If @error <> 0 Then
    MsgBox(0, "UDP Startup Error", @error, 1)
    Exit
EndIf

; --- Open Sockets ---
; Receive
$ReceiveSocket = UDPBind($MyIPaddress, $Port)
If @error <> 0 Then
    MsgBox(0, "UDP Bind Error (for receiving)", @error, 1)
    Exit
EndIf
; Send
$SendSocket = UDPOpen($BroadcastAdr, $Port)
If @error <> 0 Then
    MsgBox(0, "UDP Open Error (for sending)", @error, 1)
    Exit
EndIf

; --- Start? ---
If MsgBox(4, "Question", "Start Broadcast?") <> 6 Then Exit

; --- Main-Loop ---
$Counter = 1
While $Counter <= $MaxTries
; Sending
    $SendStatus = UDPSend($SendSocket, $SendingData)
    If $SendStatus = 0 Then
        MsgBox(0, "ERROR", "Error while sending UDP message: " & @error)
        Exit
    Else
        ConsoleWrite("sending nr " & $Counter & @CRLF)
    EndIf

; Receiving
    $ReceivedData = UDPRecv($ReceiveSocket, 20)
    If $ReceivedData <> "" Then
        ConsoleWrite("receive nr " & $Counter & ": " & $ReceivedData & @CRLF)
    Else
        If @error <> 0 Then ConsoleWrite("ReceiveError: " & @error & @CRLF)
    EndIf

    $Counter += 1
WEnd

; --- Exit ---
Exit

Func OnAutoItExit()
; --- Close Sockets ---
    UDPCloseSocket($ReceiveSocket)
    UDPCloseSocket($SendSocket)
; --- Stop UDP ---
    UDPShutdown()
EndFunc  ;==>OnAutoItExit

//edit: "code" changed to "autoit"

Edited by skyteddy
Link to comment
Share on other sites

For me, it works this way:

Client: ( send to "192.168.178.255")

;;This is the UDP Client
;;Start the server first

; Start The UDP Services
;==============================================
UDPStartup()

; Open a "SOCKET"
;==============================================
$socket = UDPOpen("192.168.178.255", 65532)
If @error <> 0 Then Exit

$n=0
While 1
    Sleep(2000)
    $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)
    UDPShutdown()
EndFunc

Server: (don't restrict on an IP)

;;This is the UDP Server
;;Start this first

; Start The UDP Services
;==============================================
UDPStartup()

; Bind to a SOCKET
;==============================================
$socket = UDPBind("", 65532)
If @error <> 0 Then Exit

While 1
    $data = UDPRecv($socket, 50)
    If $data <> "" Then
        MsgBox(0, "UDP DATA", $data, 1)
    EndIf
    sleep(100)
WEnd

Func OnAutoItExit()
    UDPCloseSocket($socket)
    UDPShutdown()
EndFunc
Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

Hello Andy,

thanks for your reply!

This is what I want to say in my first posting. To send a broadcast works fine with the LAN-specific Braodcast-address 192.168.178.255, but the router doesn't stops his boot, because he expects the broadcast from 255.255.255.255:

If you change in your code the line

$socket = UDPOpen("192.168.178.255", 65532)

to

$socket = UDPOpen("255.255.255.255", 65532)

and you will see, that you can't receive any message! But you don't get any error too. It seems, it works, but it doesn't!

255.255.255.255 is a valid broadcast-address, but with the difference, it's a LAN-independed-broadcast-address.

May it's clearer now? Sorry for my bad english.

many greetings!

R@iner

Link to comment
Share on other sites

I tried with the following script, and, to ensure my router was not part of the problem, I connected 2 PCs with an ethernet cable and turned of my WiFi then set the IPs on each PC manually.

;==============================================
 UDPStartup()
 
; Open a "SOCKET"
;==============================================
 HotKeySet("{ESC}","Xit")
 $socket = UDPOpen("255.255.255.255",5032);<----nothing received by script B
;$socket = UDPOpen("192.168.1.10",5032);<----------if I use this line instead then works ok with script B
 ConsoleWrite($socket[0] & @CRLF)
 
 If @error <> 0 Then Exit
 
 $n=0
 While 1
     Sleep(2000)
     $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)
     UDPShutdown()
 EndFunc
 
 Func Xit()
     Exit
 EndFunc

The message was received with this script

;=====Script B=========
UDPStartup()
 HotKeySet("{ESC}","xit")
 $ThisPCIP = "192.168.1.10";running script2
 $socket = UDPBind($ThisPCIP, 5032)
 If @error <> 0 Then Exit
 
 
 While 1
     $data = UDPRecv($socket, 50)
     If $data <> "" Then
         MsgBox(0, "UDP DATA", $data, 1);<-works if this IP address used by sending script, not for broadcast
     EndIf
     sleep(100)
 WEnd
 
 Func OnAutoItExit()
     UDPCloseSocket($socket)
     UDPShutdown()
 EndFunc
 
 func xit()
     Exit
 EndFunc

I didn't check with Wireshark that anything was being transmitted when sending a UDP packet in broadcast, but if it is then UDPRecv is at fault.

So I think this is a bug.

Edit: Added UPDStartup to script B which I had accidentally removed.

Edited by martin
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

Hello Martin,

thank you very much for your support!

2 remarks:

* In script A you can change your ip-adresse from 192.168.1.10 to the broadcast-address 192.168.1.255, and it works too

;$socket = UDPOpen("192.168.1.255",5032);<----------if I use this line instead then works ok with script B

* At the beginning of script B, UDPStartup() is missing

I didn't check with Wireshark that anything was being transmitted when sending a UDP packet in broadcast, but if it is then UDPRecv is at fault.

So I think this is a bug.

I test your script with wireshark, in my mind not the UDPRecv is the problem, the UDPSend or the UDPopen to 255.255.255.255 doesn't work. I can't see anything with wireshark.

kind regards

R@iner

Link to comment
Share on other sites

Hello Martin,

thank you very much for your support!

2 remarks:

* In script A you can change your ip-adresse from 192.168.1.10 to the broadcast-address 192.168.1.255, and it works too

;$socket = UDPOpen("192.168.1.255",5032);<----------if I use this line instead then works ok with script B

True, I didn't think of that at the time.

* At the beginning of script B, UDPStartup() is missing

True again, I deleted it by mistake when I removed some comments, but the script I used did have it of course. (I've put it back in now.)

I think you should report this as a bug.

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...