基本信息
源码名称:H3C交换机IP-MAC绑定助手
源码大小:0.73M
文件格式:.rar
开发语言:C#
更新时间:2024-10-19
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 2 元 
   源码介绍
基于telent协议实现的H3C交换机IP地址与mac地址的批量绑定操作,其他品牌交换机可以参考实现。

private void button1_Click(object sender, EventArgs e)
        {
            textBox1.Text = "";
            //调用方法如下:
            Telnet p = new Telnet(switcher.Text.Trim(), 23, 50);

            if (p.Connect() == false)
            {
                //Console.WriteLine("连接失败");
                textBox1.Text  = "连接失败"   "\r\n";
                return;
            }
            //等待指定字符返回后才执行下一命令
            p.WaitFor("login:");
            textBox1.Text  = p.SessionLog   "\r\n";
            p.Send(zhanghao.Text.Trim());            
            p.WaitFor("password:");
            textBox1.Text  = "\r\n"   p.WorkingData   "\r\n";
            p.Send(mima.Text.Trim());
            p.WaitFor(">");
            textBox1.Text  = "\r\n"   p.WorkingData   "\r\n";

            //切换到sys权限视图
            p.Send("sys");
            p.WaitFor("]");
            
            textBox1.Text  ="\r\n"  p.WorkingData   "\r\n";
            
            string tempstr = "";
            for (int i = 0; i < textBox2.Lines.Length; i  )
            {
                string ipmac = textBox2.Lines[i];
                string[] strArray = ipmac.Split('\t');
                //tempstr  = strArray[0]   " ==> "   strArray[1]   "\r\n";
                //区分需要绑定mac的ip地址
                if (strArray [0].StartsWith ("10.18.")) //vlan44视图
                {
                    p.Send("dhcp server ip-pool vlan44");//切换到地址池视图
                    p.WaitFor("]");
                    tempstr  = "static-bind ip-address "   strArray[0]   " mask 255.255.254.0 hardware-address "   strArray[1]   "\r\n";
                    p.Send("static-bind ip-address "   strArray[0]   " mask 255.255.254.0 hardware-address "   strArray[1]);
                    p.WaitFor("]");
                    textBox1.Text  = "\r\n"   p.WorkingData   "\r\n";
                    p.Send("quit");//退出地址池视图
                    p.WaitFor("]");
                }
                if (strArray [0].StartsWith ("10.19.")) //vlan76视图
                {
                    p.Send("dhcp server ip-pool vlan76");//切换到地址池视图
                    p.WaitFor("]");
                    tempstr  = "static-bind ip-address "   strArray[0]   " mask 255.255.255.192 hardware-address "   strArray[1]   "\r\n";
                    p.Send("static-bind ip-address "   strArray[0]   " mask 255.255.255.192 hardware-address "   strArray[1]);
                    p.WaitFor("]");
                    textBox1.Text  = "\r\n"   p.WorkingData   "\r\n";
                    p.Send("quit");//退出地址池视图
                    p.WaitFor("]");
                }
                
                textBox1.Text  = "\r\n"   p.WorkingData   "\r\n";
            }

            textBox3.Text = "总数:"   textBox2.Lines.Length.ToString();
            textBox3.Text  = "\r\n"   tempstr "\r\n 请手动进交换机检查配置是否加入并保存相应配置!";
            
        }