问题
I have a Raspberry Pi 2 with Windows 10 ioT installed. How do I set the IP Address statically in code?
回答1:
You can do this by connecting remotely to your device via Powershell and running "netsh".
You can perform a variety of tasks using the Netsh command-line utility, including configuring the IP addresses of network adapters in Windows.
Here’s how to configure a static IP address:
netsh interface ip set address "connection name" static 192.168.0.101 255.255.255.0 192.168.0.1
NOTE: The default connection names are Local Area Connection for wired adapters and Wireless Network Connection for Wi-Fi adapters. The IP address order: client IP, subnet mask, and gateway IP.
Here’s how to configure the DNS addresses:
netsh interface ip add dns "connection name" 208.67.222.222
netsh interface ip add dns "connection name" 208.67.220.220 index=2
NOTE: Remember to replace the connection names and IP addresses.
回答2:
Now it can be done directly with Windows Device Portal (with your browser)
回答3:
The short answer is that it cannot be done via code at this time.
回答4:
First start the session with iOT via Windows PowerShell Using PowerShell to connect and configure a device running Windows 10 IoT Core
Then follow How to Change Your IP Address Using PowerShell
回答5:
I guess It's a bit late, but after several research, the only solution I have found out that works so far (C#) is using ShellStream class from SSH.NET (Renci):
SshClient client = new SshClient(host, username, password);
client.Connect();
ShellStream stream = client.CreateShellStream("shellName", 80, 24, 800, 600, 1024);
Then you can manipulate the stream through StreamReader/StreamWriter and call writeLine() to introduce the cmds into the Shell.
PS: You need to install SSH.NET using the Nuget Manager, by typing the next line on the console: Install-Package SSH.NET -Pre
Hope It helps.
来源:https://stackoverflow.com/questions/31837511/how-do-i-set-the-ip-address-of-a-device-using-windows-universal-app