Java UDP translation does not work

I am trying to send UDP broadcasts to the IP address "255.255.255.255" to discover devices on my network. The program is running, but I do not see anything in Wireshark. when I change the IP address to a known IP address on my network, I see packets in Wireshark. what's happening?

This is my code:

public static void main(String args[]) throws Exception
{
    String Broadcastaddress = new String("255.255.255.255");
    int port = 9876;
    DatagramSocket serverSocket = new DatagramSocket();
    serverSocket.setBroadcast(true);
    InetAddress IPAddress = InetAddress.getByName(Broadcastaddress);
    System.out.println("Sending Discovery message to " + IPAddress + "Via UDP port " + port);

    byte[] sendData = new byte[4];
    sendData[0] = 'F';
    sendData[1] = 'I';
    sendData[2] = 'N';
    sendData[3] = 'D';

    DatagramPacket sendPacket = new DatagramPacket(sendData,sendData.length,IPAddress,port);

    while (true)
    {
        serverSocket.send(sendPacket);
        System.out.println("Packet sent");
    }


}
+5
source share
1 answer

OK, I found the answer. Windows 7 no longer supports 255.255.255.255 broadcasts, apparently this is a discovery for various threats. For broadcasting, you need to use a different approach.

This is a small explanation from Wikipedia:

IPv4 IP- . . IPv4, IP- 100.16.0.0/12 255.240.0.0, : 100.16.0.0 | 0,15.255.255 = 100.31.255.255.

IP- 255.255.255.255 . 0.0.0.0, - , . , , .

+4

All Articles