【问题标题】:Using agent name instead of IP as Address in SNMP4J在 SNMP4J 中使用代理名称而不是 IP 作为地址
【发布时间】:2016-03-07 17:56:15
【问题描述】:

我正在尝试编写一个程序,将 SNMP 查询发送到网络中的某些交换机。

使用 Net-snmp 工具,我可以使用其名称向交换机发送 get 请求,并且运行良好。但是 SNMP4J 需要 CommunityTarget 中的 IP 地址,所以我得到了 IllegalArgumentException

这是代码的相关部分:

TransportMapping transport = new DefaultUdpTransportMapping();
transport.listen();

CommunityTarget comtarget = new CommunityTarget();
comtarget.setCommunity(new OctetString("public"));
comtarget.setVersion(SnmpConstants.version1);
comtarget.setAddress(new UdpAddress("switchName")); // exception happens here
comtarget.setRetries(2);
comtarget.setTimeout(1000);

我该如何解决这个问题?

【问题讨论】:

    标签: network-programming snmp snmp4j


    【解决方案1】:

    您可以通过使用 DNS 解析来获取 IP 地址,就像这样 answer 说:

    InetAddress address = InetAddress.getByName(switchName); 
    System.out.println(address.getHostAddress());
    

    【讨论】:

      猜你喜欢
      • 2013-11-11
      • 2016-11-11
      • 2020-05-19
      • 1970-01-01
      • 2017-07-16
      • 2011-10-15
      • 1970-01-01
      • 1970-01-01
      • 2017-01-03
      相关资源
      最近更新 更多