Ejemplo n.º 1
0
  /** 按IP找到接口 */
  public IfEntity getIfEntityByIP(String ip) {
    if (ifEntityList == null || ifEntityList.size() == 0) return null;

    IfEntity ifEntity = null;
    for (int i = 0; i < ifEntityList.size(); i++) {
      IfEntity obj = (IfEntity) ifEntityList.get(i);
      if (obj.getIpList() != null) {
        if (obj.getIpList().split(",").length > 0) {
          int flag = 0;
          String IPS[] = obj.getIpList().split(",");
          for (int k = 0; k < IPS.length; k++) {
            // SysLogger.info(this.getIpAddress()+"含有接口地址"+IPS[k]+"===="+ip);
            if (IPS[k].equalsIgnoreCase(ip)) {
              ifEntity = obj;
              flag = 1;
              break;
            }
          }
          if (flag == 1) break;
        } else {
          // SysLogger.info(this.getIpAddress()+"含有接口地址"+obj.getIpList()+"====="+ip);
          if (obj.getIpList().equalsIgnoreCase(ip)) {
            ifEntity = obj;
            break;
          }
        }
      }
    }
    return ifEntity;
  }
Ejemplo n.º 2
0
  /** 按端口找到一个接口 */
  public IfEntity getIfEntityByPort(String port) {
    if (port == null) return null;
    if (ifEntityList == null || ifEntityList.size() == 0) return null;

    IfEntity ifEntity = null;
    for (int i = 0; i < ifEntityList.size(); i++) {
      IfEntity obj = (IfEntity) ifEntityList.get(i);
      if (obj.getPort().equals(port)) {
        ifEntity = obj;
        break;
      }
    }
    if (ifEntity == null) SysLogger.info(ipAddress + "中没有端口为" + port + "的接口");
    return ifEntity;
  }
Ejemplo n.º 3
0
  /** 按描述找到一个接口 */
  public IfEntity getIfEntityByDesc(String desc) {
    if (desc == null) return null;
    if (ifEntityList == null || ifEntityList.size() == 0) return null;

    IfEntity ifEntity = null;
    for (int i = 0; i < ifEntityList.size(); i++) {
      IfEntity obj = (IfEntity) ifEntityList.get(i);
      if (obj.getDescr().equals(desc)) {
        ifEntity = obj;
        break;
      }
    }
    if (ifEntity == null) SysLogger.info(ipAddress + "中没有端口描述为" + desc + "的接口");
    return ifEntity;
  }
Ejemplo n.º 4
0
  /** 按接口索引找到接口 */
  public IfEntity getIfEntityByIndex(String ifIndex) {
    if (ifEntityList == null || ifEntityList.size() == 0) return null;

    IfEntity ifEntity = null;
    for (int i = 0; i < ifEntityList.size(); i++) {
      IfEntity obj = (IfEntity) ifEntityList.get(i);
      if (obj.getIndex().equals(ifIndex)) {
        ifEntity = obj;
        break;
      }
    }
    if (ifEntity == null) SysLogger.info(ipAddress + "中没有索引为" + ifIndex + "的接口");

    return ifEntity;
  }
Ejemplo n.º 5
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);
     }
   }
 }