1.登录交换机:
using System;
using Huawei.IES.NetAcad.Device;
namespace HuaweiSwitchDemo
{
class Program
{
static void Main(string[] args)
{
// 创建连接对象
IConnection connection = new Connection("192.168.1.1", "admin", "password");
// 登录交换机
if (connection.Login())
{
Console.WriteLine("登录成功!");
}
else
{
Console.WriteLine("登录失败!");
}
}
}
}
2.配置 VLAN:
using System;
using Huawei.IES.NetAcad.Device;
namespace HuaweiSwitchDemo
{
class Program
{
static void Main(string[] args)
{
// 创建连接对象
IConnection connection = new Connection("192.168.1.1", "admin", "password");
// 登录交换机
if (connection.Login())
{
Console.WriteLine("登录成功!");
// 创建 VLAN 对象
Ivlan vlan = new Ivlan(connection);
// 添加 VLAN
if (vlan.AddVlan(10, "VLAN10"))
{
Console.WriteLine("添加 VLAN10 成功!");
}
else
{
Console.WriteLine("添加 VLAN10 失败!");
}
if (vlan.AddVlan(20, "VLAN20"))
{
Console.WriteLine("添加 VLAN20 成功!");
}
else
{
Console.WriteLine("添加 VLAN20 失败!");
}
if (vlan.AddVlan(30, "VLAN30"))
{
Console.WriteLine("添加 VLAN30 成功!");
}
else
{
Console.WriteLine("添加 VLAN30 失败!");
}
}
else
{
Console.WriteLine("登录失败!");
}
}
}
}
3.配置端口:
using System;
using Huawei.IES.NetAcad.Device;
namespace HuaweiSwitchDemo
{
class Program
{
static void Main(string[] args)
{
// 创建连接对象
IConnection connection = new Connection("192.168.1.1", "admin", "password");
// 登录交换机
if (connection.Login())
{
Console.WriteLine("登录成功!");
// 创建端口对象
Iport port = new Iport(connection);
// 配置端口 1/0/1 为 access 模式,加入 VLAN10
if (port.SetAccessMode("GigabitEthernet0/0/1", 10))
{
Console.WriteLine("配置端口 1/0/1 成功!");
}
else
{
Console.WriteLine("配置端口 1/0/1 失败!");
}
// 配置端口 1/0/2 为 trunk 模式,允许通过 VLAN10、VLAN20、VLAN30
if (port.SetTrunkMode("GigabitEthernet0/0/2", new int[] { 10, 20, 30 }))
{
Console.WriteLine("配置端口 1/0/2 成功!");
}
else
{
Console.WriteLine("配置端口 1/0/2 失败!");
}
}
else
{
Console.WriteLine("登录失败!");
}
}
}
}