简体   繁体   English

如何在snmp4j中使用外部IP创建snmp客户端?

[英]How to create snmp client using external ip in snmp4j?

I want create snmp client to some devices. 我想为某些设备创建snmp客户端。 However devices are not directly accessible from localhost . 但是,不能从localhost直接访问设备。 Want to use external ip to create the snmp client(session). 想要使用外部ip创建snmp客户端(会话)。 How can I fullfill it using SNMP4j. 如何使用SNMP4j完整填写。

Below is the code snippet I use to create snmp client. 以下是用于创建snmp客户端的代码段。

 public SNMPClient(String address) {
    super();
    this.address = address;
    try {
        start();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

private void start() throws IOException {

    TransportMapping transport = new DefaultUdpTransportMapping();

    // Create Target Address object
    this.target = new CommunityTarget();
    target.setCommunity(new OctetString("public"));
    target.setVersion(SnmpConstants.version2c);
    target.setAddress(new UdpAddress(address));
    target.setRetries(2);
    target.setTimeout(50000);
    snmp = new Snmp(transport);

    transport.listen();
}

I tried to give extrenal IP during transport creation like shown below 我试图在传输创建过程中提供外部IP,如下所示

TransportMapping transport = new DefaultUdpTransportMapping(new UdpAddress("192.8.8.8"));

But does not seems to be working. 但是似乎没有用。

Please suggest how can I go ahead? 请提出我该如何继续?

Thanks in advance, Brinal 在此先感谢,Brinal

You're missing listening port definition in your code. 您在代码中缺少侦听端口定义。 This is how it should work 这应该是这样的

TransportMapping transport = new DefaultUdpTransportMapping(new UdpAddress("192.8.8.8/161"));
  • 161 port for listening to standard snmp agent query responses 161端口,用于侦听标准的snmp代理查询响应
  • 162 listening for snmp agent trap messages 162监听snmp代理陷阱消息

But iam not sure if i fully understand your question. 但是我不确定我是否完全理解你的问题。 SNMP clients (managers) are used to query snmp agents running on network devices (such as routers, PCs, printers etc) and receive responses for these queries. SNMP客户端(管理器)用于查询在网络设备(例如路由器,PC,打印机等)上运行的snmp代理,并接收这些查询的响应。 Managers also listen for trap messages fired by snmp agents. 经理还监听snmp代理触发的陷阱消息。 Is your purpose to create snmp manager or agent? 您是要创建snmp管理器还是代理?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM