日期:2011-07-23  浏览次数:20495 次

语言c# ,运行需要 .Net Framework 2.0

在很多行业或公司,会通过限制ip的方法,使局域网内一部分ip可以上外网。本方案通过修改ip和网卡地址达到在别人不知不觉地情况下共用一个ip上网。
==================代码如下: =======================
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32;
using System.Windows;
using System.Management;
using System.Net.NetworkInformation;
using System.ServiceProcess;

namespace ReworkMAC
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            listBox1.Items.Clear();
            RegistryKey macRegistry = Registry.LocalMachine.OpenSubKey("SYSTEM").OpenSubKey("CurrentControlSet").OpenSubKey("Control").OpenSubKey("Class").OpenSubKey("{4D36E972-E325-11CE-BFC1-08002bE10318}");//mac的注册表建所在
            foreach (string mrk in macRegistry.GetSubKeyNames())
            {
                listBox1.Items.Add(mrk);
            }
            IPGlobalProperties computerProperties = IPGlobalProperties.GetIPGlobalProperties();
           
            textBox4.Text = computerProperties.HostName;
            NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
            foreach (NetworkInterface adapter in nics)
            {
                if (adapter.Name=="本地连接")
                {
                    textBox2.Text = adapter.Description;
                    textBox3.Text = adapter.GetPhysicalAddress().ToString();
                    textBox10.Text = adapter.Id;
                }
        //        listBox3.Items.Add(adapter.Id+" 接口类型  "+adapter.NetworkInterfaceType.ToString());
            }
            /////////////////////////////////////////////////////////////////
            ///一下这一段有待以后研究,现在还没有看懂
            ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfigur