• 大小: 60KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-16
  • 语言: 其他
  • 标签: 源码  Mac修改  C#  .NET  

资源简介

根据注册表修改Mac地址,然后将本地连接进行停用和启用来达到Mac地址的正确修改

资源截图

代码片段和文件信息

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 Shell32;
using System.Threading;
using System.IO;

namespace WindowsFormsApplication2
{
    public partial class MacModifyForm : Tokay.SystemUI.Dialogs.BasicDialog
    {
        private const string NETWORKADDRESS_KEY = @“SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}\0007“;
        private const string NETWORKADDRESS_NAME = “NetworkAddress“;

        private const string discVerb = “禁用(&B)“;
        private const string connVerb = “启用(&A)“;

        private readonly string bufferFile = Application.StartupPath + “\\buffer.dat“;
        private readonly List bufferIp = new List();

        public MacModifyForm()
        {
            InitializeComponent();

            if (File.Exists(bufferFile))
            {
                StreamReader sr = new StreamReader(bufferFile);
                while (!sr.EndOfStream)
                {
                    string line = sr.ReadLine();
                    if (line.Length > 0)
                    {
                        bufferIp.Add(line.Trim());
                    }
                }
            }
        }

        private void MacModifyForm_Load(object sender EventArgs e)
        {
            this.textBox1.Text = ReadMac();
            this.btnOK.Enabled = false;
        }

        private string ReadMac()
        {
            RegistryKey HKLM = Registry.LocalMachine;
            try
            {
                RegistryKey Reg = HKLM.OpenSubKey(NETWORKADDRESS_KEY);
                object o = Reg.GetValue(NETWORKADDRESS_NAME);
                return o.ToString();
            }
            catch
            {
                return string.Empty;
            }
        }

        private void SetMac(string mac)
        {
            RegistryKey HKLM = Registry.LocalMachine;
            RegistryKey Reg = HKLM.OpenSubKey(NETWORKADDRESS_KEY true);
            Reg.SetValue(NETWORKADDRESS_NAME mac);
        }

        private void RestartMac()
        {
            this.StopMac();
            Thread.Sleep(3000);
            this.StartMac();
        }

        private void StartMac()
        {
            Shell sh = new Shell32.Shell();
            Folder folder;
            Folder fd;
            folder = sh.NameSpace(3);
            foreach (FolderItem myItem in folder.Items())
            {
                if (myItem.Name == “网络连接“)
                {
                    fd = (Folder)myItem.GetFolder;
                    //禁用网络
                    foreach (FolderItem fi in fd.Items())
                    {
                        foreach (FolderItemVerb Fib in fi.Verbs())
                        {
                            //启用网络
                            if (Fib.Nam

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

     文件       7158  2009-02-13 15:45  MacModifyForm.cs

     文件       7762  2009-02-13 15:38  MacModifyForm.Designer.cs

     文件     978199  2009-02-13 15:38  MacModifyForm.resx

----------- ---------  ---------- -----  ----

               993119                    3


评论

共有 条评论