• 大小: 251KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-13
  • 语言: C#
  • 标签:   IP  DNS  

资源简介

用C#设计的一键可更换本地连接的IP,DNS,网关,子网掩码,还可以恢复默认设置,即动态获取.支持按键F2:设置静态IP, F3:设置动态获取,ALT+X退出.

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Management;

namespace 一键换IP
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }


        
        private void button1_Click(object sender EventArgs e)
        {
            Managementbaseobject inPar = null;
            Managementbaseobject outPar = null;
            ManagementClass mc = new ManagementClass(“Win32_NetworkAdapterConfiguration“);
            ManagementobjectCollection moc = mc.GetInstances();
            foreach (Managementobject mo in moc)
            {
               if (!(bool)mo[“IPEnabled“])
                   continue;

                //设置ip地址和子网掩码   
                inPar = mo.GetMethodParameters(“EnableStatic“);
               
                string ip = ““;
                ip = numericUpDown1.Value.ToString() + “.“ + numericUpDown2.Value.ToString() + “.“ + numericUpDown3.Value.ToString() + “.“ + numericUpDown4.Value.ToString();
                inPar[“IPAddress“] = new string[] { ip };// 1.备用 2.IP  
                
                string ym = ““;
                ym = numericUpDown8.Value.ToString() + “.“ + numericUpDown7.Value.ToString() + “.“ + numericUpDown6.Value.ToString() + “.“ + numericUpDown5.Value.ToString(); 
                inPar[“SubnetMask“] = new string[] { ym };
                outPar = mo.InvokeMethod(“EnableStatic“ inPar null);

                //设置网关地址   
                inPar = mo.GetMethodParameters(“SetGateways“);

                string wg = ““;

                wg = numericUpDown12.Value.ToString() + “.“ + numericUpDown11.Value.ToString() + “.“ + numericUpDown10.Value.ToString() + “.“ + numericUpDown9.Value.ToString(); 

                inPar[“DefaultIPGateway“] = new string[] { wg }; // 1.网关;2.备用网关  
                outPar = mo.InvokeMethod(“SetGateways“ inPar null);

                //设置DNS   
                inPar = mo.GetMethodParameters(“SetDNSServerSearchOrder“);

               string dns1 = numericUpDown16.Value.ToString() + “.“ + numericUpDown15.Value.ToString() + “.“ + numericUpDown14.Value.ToString() + “.“ + numericUpDown13.Value.ToString();
               string dns2 = numericUpDown20.Value.ToString() + “.“ + numericUpDown19.Value.ToString() + “.“ + numericUpDown18.Value.ToString() + “.“ + numericUpDown17.Value.ToString(); 
                inPar[“DNSServerSearchOrder“] = new string[] { dns1 dns2 }; // 1.DNS 2.备用DNS  
                outPar = mo.InvokeMethod(“SetDNSServerSearchOrder“ inPar null);
                break;
            }
        }

        private void button2_Click(object sender EventArgs e)
        {
            ManagementClass wmi = new ManagementClass(“Win32_NetworkAdapterConfiguration“);
            ManagementobjectCollection moc = wmi.GetInstances(

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       5612  2013-12-24 17:04  一键换IP\一键换IP\Properties\Resources.resx

     文件        249  2013-12-24 17:04  一键换IP\一键换IP\Properties\Settings.settings

     文件       1194  2013-12-24 17:04  一键换IP\一键换IP\Properties\AssemblyInfo.cs

     文件       2878  2013-12-24 17:04  一键换IP\一键换IP\Properties\Resources.Designer.cs

     文件       1096  2013-12-24 17:04  一键换IP\一键换IP\Properties\Settings.Designer.cs

     文件       7846  2013-12-24 20:21  一键换IP\一键换IP\Form1.resx

     文件      26555  2013-12-24 20:21  一键换IP\一键换IP\Form1.Designer.cs

     文件       4424  2013-12-24 19:52  一键换IP\一键换IP\一键换IP.csproj

     文件       5632  2005-11-11 22:25  一键换IP\一键换IP\bin\Debug\一键换IP.vshost.exe

     文件      28672  2013-12-24 19:01  一键换IP\一键换IP\bin\Debug\一键换IP.exe

     文件      30208  2013-12-24 19:01  一键换IP\一键换IP\bin\Debug\一键换IP.pdb

     文件       5632  2005-11-11 22:25  一键换IP\一键换IP\bin\Release\一键换IP.vshost.exe

     文件      28672  2013-12-24 20:21  一键换IP\一键换IP\bin\Release\一键换IP.exe

     文件      28160  2013-12-24 20:21  一键换IP\一键换IP\bin\Release\一键换IP.pdb

     文件       2145  2013-12-24 20:21  一键换IP\一键换IP\bin\Release\一键换IP.exe.manifest

     文件       1486  2013-12-24 20:21  一键换IP\一键换IP\bin\Release\一键换IP.application

     文件       1486  2013-12-24 20:21  一键换IP\一键换IP\bin\Release\一键换IP.vshost.application

     文件       2145  2013-12-24 20:21  一键换IP\一键换IP\bin\Release\一键换IP.vshost.exe.manifest

     文件       5816  2013-12-24 19:57  一键换IP\一键换IP\bin\Release\一键换IP.publish\一键换IP_1_0_0_1\一键换IP.exe.manifest

     文件      28672  2013-12-24 19:56  一键换IP\一键换IP\bin\Release\一键换IP.publish\一键换IP_1_0_0_1\一键换IP.exe.deploy

     文件     423880  2013-12-24 19:57  一键换IP\一键换IP\bin\Release\一键换IP.publish\setup.exe

     文件       5213  2013-12-24 19:57  一键换IP\一键换IP\bin\Release\一键换IP.publish\一键换IP.application

     文件       1716  2013-12-24 18:46  一键换IP\一键换IP\obj\Debug\一键换IP.Form1.resources

     文件        180  2013-12-24 18:46  一键换IP\一键换IP\obj\Debug\一键换IP.Properties.Resources.resources

     文件        842  2013-12-24 18:46  一键换IP\一键换IP\obj\Debug\一键换IP.csproj.GenerateResource.Cache

     文件      28672  2013-12-24 19:01  一键换IP\一键换IP\obj\Debug\一键换IP.exe

     文件      30208  2013-12-24 19:01  一键换IP\一键换IP\obj\Debug\一键换IP.pdb

     文件       3178  2013-12-24 20:22  一键换IP\一键换IP\obj\一键换IP.csproj.FileListAbsolute.txt

     文件       1716  2013-12-24 20:21  一键换IP\一键换IP\obj\Release\一键换IP.Form1.resources

     文件        180  2013-12-24 19:19  一键换IP\一键换IP\obj\Release\一键换IP.Properties.Resources.resources

............此处省略27个文件信息

评论

共有 条评论