コード例 #1
0
 public void analsysNDPHost(Host node, Host host) {
   if (host.getNdpHash() == null)
     host.setNdpHash(snmp.getNDPTable(host.getIpAddress(), host.getCommunity()));
   // 判断该NDP中是否包含node的MAC地址,若包含,则说明node是跟该设备直接连接关系
   Hashtable hostNDPHash = host.getNdpHash();
   if (host.getMac() == null) {
     String descr = (String) hostNDPHash.get(node.getMac());
     IfEntity nodeIfEntity = node.getIfEntityByDesc(descr);
     Link link = new Link();
     link.setStartId(node.getId());
     link.setStartIndex(nodeIfEntity.getIndex());
     link.setStartIp(node.getIpAddress());
     link.setStartPhysAddress(node.getMac()); // 记录下起点的mac
     link.setStartDescr(descr);
     link.setEndIp(host.getIpAddress());
     DiscoverEngine.getInstance().addHost(host, link);
   } else {
     if (node.getNdpHash() != null) {
       if (node.getNdpHash().containsKey(host.getMac())) {
         String hostdesc = (String) node.getNdpHash().get(host.getMac());
         String descr = (String) hostNDPHash.get(node.getMac());
         IfEntity nodeIfEntity = node.getIfEntityByDesc(descr);
         IfEntity hostIfEntity = host.getIfEntityByDesc(hostdesc);
         Link link = new Link();
         link.setStartId(node.getId());
         link.setStartIndex(nodeIfEntity.getIndex());
         link.setStartIp(node.getIpAddress());
         link.setStartPhysAddress(node.getMac()); // 记录下起点的mac
         link.setStartDescr(descr);
         link.setEndIndex(hostIfEntity.getIndex());
         link.setEndIp(host.getIpAddress());
         link.setEndPhysAddress(hostIfEntity.getPhysAddress());
         link.setEndDescr(hostdesc);
         DiscoverEngine.getInstance().addHost(host, link);
       } else {
         String descr = (String) hostNDPHash.get(node.getMac());
         IfEntity nodeIfEntity = node.getIfEntityByDesc(descr);
         Link link = new Link();
         link.setStartId(node.getId());
         link.setStartIndex(nodeIfEntity.getIndex());
         link.setStartIp(node.getIpAddress());
         link.setStartPhysAddress(node.getMac()); // 记录下起点的mac
         link.setStartDescr(descr);
         link.setEndIp(host.getIpAddress());
         DiscoverEngine.getInstance().addHost(host, link);
       }
     } else {
       String descr = (String) hostNDPHash.get(node.getMac());
       IfEntity nodeIfEntity = node.getIfEntityByDesc(descr);
       Link link = new Link();
       link.setStartId(node.getId());
       link.setStartIndex(nodeIfEntity.getIndex());
       link.setStartIp(node.getIpAddress());
       link.setStartPhysAddress(node.getMac()); // 记录下起点的mac
       link.setStartDescr(descr);
       link.setEndIp(host.getIpAddress());
       DiscoverEngine.getInstance().addHost(host, link);
     }
   }
 }