您可以通过这种方式使用 telnet 程序谷歌“MinimalisticTelnet”并使用示例来理解这个解决方案
另一种方法是使用 SNMP 协议,例如此示例:注意:对于使用 snmp,我得到更改并自定义 SnmpSharpNet 库,并在我的程序中调用它
using SnmpSharpNet;
然后编写此代码以禁用从 1 到 6 的端口:
Console.WriteLine("Ports Disabler ");
UdpTarget target = new UdpTarget((IPAddress)new IpAddress("192.168.1.200"));
Pdu pdu = new Pdu(PduType.Set);
pdu.VbList.Add(new Oid("1.3.6.1.2.1.2.2.1.7.1"), new Integer32(2));
pdu.VbList.Add(new Oid("1.3.6.1.2.1.2.2.1.7.2"), new Integer32(2));
pdu.VbList.Add(new Oid("1.3.6.1.2.1.2.2.1.7.3"), new Integer32(2));
pdu.VbList.Add(new Oid("1.3.6.1.2.1.2.2.1.7.4"), new Integer32(2));
pdu.VbList.Add(new Oid("1.3.6.1.2.1.2.2.1.7.5"), new Integer32(2));
pdu.VbList.Add(new Oid("1.3.6.1.2.1.2.2.1.7.6"), new Integer32(2));
AgentParameters aparam = new AgentParameters(SnmpVersion.Ver2, new OctetString("2645"));
SnmpV2Packet response;
try
{
// Send request and wait for response
response = target.Request(pdu, aparam) as SnmpV2Packet;
}
catch (Exception ex)
{
// If exception happens, it will be returned here
Console.WriteLine(String.Format("Request failed with exception: {0}", ex.Message));
target.Close();
return;
}
// Make sure we received a response
if (response == null)
{
Console.WriteLine("Error in sending SNMP request.");
}
else
{
// Check if we received an SNMP error from the agent
if (response.Pdu.ErrorStatus != 0)
{
Console.WriteLine(String.Format("SNMP agent returned ErrorStatus {0} on index {1}",
response.Pdu.ErrorStatus, response.Pdu.ErrorIndex) + response.ToString());
}
else
{
// Everything is ok. Agent will return the new value for the OID we changed
Console.WriteLine(String.Format("Agent response {0}: {1}",
response.Pdu[0].Oid.ToString(), response.Pdu[0].Value.ToString()));
}
}
我希望这个答案是有用的,可以帮助你,