Java – perform UPnP scan without returning to Philips hue Bridge

I tried to implement my own UPnP scan. It mainly works and proves that this is not me. I have a Windows program that allows you to send packets and see what response you have

I send a packet on port 1900 to 239.255 255.250, I send the following data:

M-SEARCH * HTTP/1.1
Host: 239.255.255.250:1900
Man: "ssdp:discover"
MX: 10
ST: ssdp:all

Just need further information. In my java code (Android), I have the following, but I get the same response as the packet test application:

try
        {
            byte[] sendData = new byte[1024];
            //byte[] receiveData = new byte[1024];
            byte[] receiveData;
            String mSearch = "M-SEARCH * HTTP/1.1\r\nHost: 239.255.255.250:1900\r\nMan: \"ssdp:discover\"\r\nMX: 10\r\nST: ssdp:all\r\n\r\n";
            sendData = mSearch.getBytes();

            DatagramPacket sendPacket = new DatagramPacket(sendData,sendData.length,InetAddress.getByName("239.255.255.250"),1900);

            DatagramSocket clientSocket = new DatagramSocket();
            clientSocket.send(sendPacket);

            while (keepGoing)
            {
                receiveData = new byte[1024];
                receivePacket = new DatagramPacket(receiveData,receiveData.length);
                clientSocket.receive(receivePacket);

                String response = new String(receivePacket.getData());

                if (response == null || response.length() == 0)
                {
                    keepGoing = false;
                }
                else
                {
                    iupnpScan.updateText(response);
                }

            }
            iupnpScan.complete(true);
            return true;
        }
        catch (UnkNownHostException ex)
        {
            Log.e("MainActivity","UnkNown Host Exception: " + ex.toString());
        }
        catch (SocketException ex)
        {
            Log.e("MainActivity","Socket Exception: " + ex.toString());
        }
        catch (IOException ex)
        {
            Log.e("MainActivity","IO Exception: " + ex.toString());
        }
        iupnpScan.complete(false);
        return false;

I am receiving some devices back, such as my smart TV, router and NAS, but phyips hue bridge has never returned in the reply

Whether Philips hue bridge realizes the difference of UPnP, I can see what the response is and what it needs to find

thank you

Solution

Although Philips site notes support UPnP, I don't know if it is true

I will try to scan the whole network and test IP through IP Yes, I know, this is not what the standard says, but the reality is sometimes crazy

This discovery has been implemented in this way

I used to program a web search (looking for a raspberry PI). The best way I can use is to match the MAC address and start with the address I know Fortunately, Philips publish their MAC addresses range

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>