110,535
社区成员
发帖
与我相关
我的任务
分享
Process p = new Process();
p.StartInfo.FileName = "netsh";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
p.Start();
p.OutputDataReceived += delegate(object Osender, DataReceivedEventArgs arg)
{
label2.Text += arg.Data + "\n";
};
p.ErrorDataReceived += delegate(object Osender, DataReceivedEventArgs arg)
{
label2.Text += arg.Data + "\n";
};
p.BeginOutputReadLine();
p.BeginErrorReadLine();
p.StandardInput.WriteLine("interface ip");
p.StandardInput.WriteLine(ConfigOfIP);
p.StandardInput.WriteLine();
p.StandardInput.WriteLine(ConfigOfDNS);
p.Exited+= delegate(object sender,EventArgs e)
{
MessageBox.Show("finished");
};
p.StandardInput.WriteLine("exit");
p.WaitForExit();
label1.Text = GetMyIp();
button1.Enabled = true;
ConfigOfIP = "set address \"本地连接\" static 192.168.1.15 255.255.255.0 192.138.1.1 1“;
ConfigOfDNS = "set dns \"本地连接\" dhcp";
Process p = new Process();
p.StartInfo.FileName = "cmd";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
p.Start();
p.OutputDataReceived += delegate(object Osender, DataReceivedEventArgs arg)
{
label2.Text += arg.Data + "\n";
};
p.ErrorDataReceived += delegate(object Osender, DataReceivedEventArgs arg)
{
label2.Text += arg.Data + "\n";
};
p.BeginOutputReadLine();
p.BeginErrorReadLine();
p.StandardInput.WriteLine("netsh");
p.StandardInput.WriteLine("interface ip");
p.StandardInput.WriteLine(ConfigOfIP);
p.StandardInput.WriteLine(ConfigOfDNS);
p.StandardInput.WriteLine("exit");
p.StandardInput.WriteLine("exit");
p.WaitForExit();
label1.Text = GetMyIp();
NetworkInterface[] adapter = NetworkInterface.GetAllNetworkInterfaces();
IPInterfaceProperties ipp = adapter[0].GetIPProperties();
IPv4InterfaceProperties ip4ip = ipp.GetIPv4Properties();
if (ip4ip.IsDhcpEnabled)
radioButton1.Checked = true;
else
radioButton2.Checked = true;