Reputation: 138071
I have a computer on my network on which I would like to automatically configure proxy settings. My Windows computer will serve as the proxy server.
To do that, I can use a command to remote into that first computer and tell it to connect to my main computer using its IP address. This goes something like:
PS> remote-cmd 192.168.0.101 "set-proxy-address 192.168.0.100:8888"
where 192.168.0.101 is the computer I'm trying to configure, and 192.168.0.100 is my Windows machine's IP address on the same network.
As far as automation goes, however, I have multiple network adapters and multiple IP addresses. For the sake of the example, say that my Windows machine has these two IP addresses:
The target machine, however, is only on the 192... network, so I need to give it my 192... ip address, not the 10... one, as the proxy server.
How can I write a script (preferably with Powershell, but anything Powershell-compatible like C# would make me happy too) that will automatically determine, given the remote machine's IP address and the route that it will use, the correct proxy address that should be passed?
Upvotes: 0
Views: 505
Reputation: 138071
Since Windows 10 and Server 2012 R2, Powershell has a Find-NetRoute
commandlet that seems to do that.
$routeInfo = Find-NetRoute -RemoteIPAddress 192.168.0.101
On success, $routeInfo[0]
is the interface through which the data will go, and $routeInfo[1]
is the route that matched the remote IP address.
Upvotes: 2