您可以使用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()));
}
}
我希望這個答案是有用的,可以幫助你,
謝謝尼爾,你的信息非常有用。我現在要去研究它們。 你說得對,我認爲第二種選擇可能是我正在考慮的。但正如你建議的第一個,我會嘗試。 :P – tingfungc 2012-02-07 08:20:08
很高興能有所幫助。 – 2012-02-07 09:02:45
我試圖啓用telnet連接併成功連接到交換機。所以編寫一個C#程序來做端口切換將非常簡單。感謝尼爾爲您的選擇1。 此外,我的老闆仍然想在這個問題中使用SNMP,所以現在我要試試option2。 所以1.3.6.1.2.1.2.2.1.7是目標OID,它是一個整數類型的值。但是我有24個端口(FastEthernet 1-24),所以應該有24個值和OID? – tingfungc 2012-02-08 04:01:59