WebClient and several network adapters

I use WebClient to try to get a string response from a piece of equipment connected locally to my computer. My computer has a network adapter connected to the local network, and a second adapter connected only to my kit.

If I use IE with the URL: http://169.254.103.127/set.cmd?user=admin+pass=12345678+cmd=getpower I am returning the string in response. I am trying to use the following code snippet to accomplish the same thing:

using (WebClient client = new WebClient())
        {
            client.Proxy = WebRequest.DefaultWebProxy;
            client.Credentials = CredentialCache.DefaultCredentials;
            client.Proxy.Credentials = CredentialCache.DefaultCredentials;

            client.Headers["User-Agent"] =
            "Mozilla/4.0 (Compatible; Windows NT 5.1; MSIE 6.0) " +
            "(compatible; MSIE 6.0; Windows NT 5.1; " +
            ".NET CLR 1.1.4322; .NET CLR 2.0.50727)";

            String test = client.DownloadString(@"http://169.254.103.127/set.cmd?user=admin+pass=12345678+cmd=getpower");
        }

This snippet works if I disconnect my network adapter connected to my local network, but otherwise it doesn’t work.

Can someone explain why this is happening and what I need to do to forward the request to the correct network?

+4
2

- , :

private String SendCommand(String command)
    {
        String response = null;

        using (WebClient client = new WebClient())
        {
            client.Proxy = null;
            response = client.DownloadString(command);
        }

        return response;
    }
+1

, .

(, ) → - > IP v4 → → → , 900.

- , , ( , , )

, , , . DHCP, Windows , link-local address.

, (LAN), 169.254.103.127 .

, :

   route print 

, :

          0.0.0.0          0.0.0.0      192.168.1.1    192.168.1.100    276  // Default gateway
        127.0.0.0        255.0.0.0         On-link         127.0.0.1    306
        127.0.0.1  255.255.255.255         On-link         127.0.0.1    306
  127.255.255.255  255.255.255.255         On-link         127.0.0.1    306
      169.254.0.0      255.255.0.0         On-link    169.254.239.60    261 // Where you want to go
   169.254.239.60  255.255.255.255         On-link    169.254.239.60    261
  169.254.255.255  255.255.255.255         On-link    169.254.239.60    261
      192.168.1.0    255.255.255.0         On-link     192.168.1.100    276
    192.168.1.100  255.255.255.255         On-link     192.168.1.100    276
    192.168.1.255  255.255.255.255         On-link     192.168.1.100    276

276 > 261, 169.254.103.127 lan 192.168.1.100 169.254.239.60

+2

Source: https://habr.com/ru/post/1615264/


All Articles