Network programming 使用SNMP LLDP查找邻居

Network programming 使用SNMP LLDP查找邻居,network-programming,ip,snmp,network-monitoring,Network Programming,Ip,Snmp,Network Monitoring,我有几个开关(Hirschmann Mach1040,RS40)连接在一起。所以我想用snmp删除端口x上连接的邻居交换机的mac地址/ip地址。是否有一个lldp mib_值告诉我交换机上特定端口的附近mac或ip 非常感谢你的帮助 我认为您需要lldpRemLocalPortNum,它的语法类型是LldpPortNumber。LldpPortNumber的定义是: A port number has no mandatory relationship to an

我有几个开关(Hirschmann Mach1040,RS40)连接在一起。所以我想用snmp删除端口x上连接的邻居交换机的mac地址/ip地址。是否有一个lldp mib_值告诉我交换机上特定端口的附近mac或ip


非常感谢你的帮助

我认为您需要lldpRemLocalPortNum,它的语法类型是LldpPortNumber。LldpPortNumber的定义是:

        A port number has no mandatory relationship to an
        InterfaceIndex object (of the interfaces MIB, IETF RFC 2863).
        If the LLDP agent is a IEEE 802.1D, IEEE 802.1Q bridge, the
        LldpPortNumber will have the same value as the dot1dBasePort
        object (defined in IETF RFC 1493) associated corresponding
        bridge port.  If the system hosting LLDP agent is not an
        IEEE 802.1D or an IEEE 802.1Q bridge, the LldpPortNumber
        will have the same value as the corresponding interface's
        **InterfaceIndex** object.
InterfaceIndex是IF-MIB::ifIndex,它应该映射到设备上的正确接口。这有帮助吗?

这里有更多的细节(我需要一个大文本框)。假设您有上面评论中提到的条目:

lldpRemTable.lldpRemEntry.lldpRemChassisId.1325376015.2.1 ec e5 55 32 20 88
请注意,lldpRemTable的索引为:

    INDEX   {
       lldpRemTimeMark,
       lldpRemLocalPortNum,
       lldpRemIndex
    }
在上面的示例中,您要求为远程入口(其机箱mac,ec e5 55 32 20 88)提供LLDPremchassiId(远程的机箱id)。1325376015是lldpRemTimeMark表索引(查找远程设备时的时间值),2是lldpRemLocalPortNum表索引(查找远程设备时的本地端口号)

lldpRemLocalPortNum的类型/文本约定为LldpPortNum。因此,在lldpLocPortTable(也是LldpPortNum的类型)中还应该有一个lldpLocPortNum==2的条目(可能还有一个IF-MIB::ifIndex==2)。因此,lldpLocPortTable.lldpLocPortDesc.2将是您在其上发现远程端口的端口描述。i、 e:

lldpLocPortTable.lldpLocPortDesc.2 = "FastEthernet2 (eth2)"

这就是映射的方式。

这段代码在包含ip地址的列表中的设备上遍历LLDP oid,并将相邻关系添加到并行阵列。 前任;(每个标题都是ArrayList) 主机名主机接口NeigbourName邻居 sw2960 fa0/1 HP-98765以太网0/4

   package NDMSMain;

import java.io.IOException;
import java.util.ArrayList;

import SNMPHandler.SNMPManager;
import SNMPHandler.SNMPWalk;
import TopologyHandler.WriteXMLFile;

public class LldpDiscovery {

    static SNMPWalk t1 = new SNMPWalk();
    public static String LLDP_OID = "1.0.8802.1.1.2.1.4.1.1";
    public static String snmpCheck = null; //MODEL
    public static String devicePid = null;  //Product Id

    public static ArrayList<String> topologyNodeId = new ArrayList<String>();
    public static ArrayList<String> lldpHostName = new ArrayList<String>();
    public static ArrayList<String> lldpHostInt = new ArrayList<String>();
    public static ArrayList<String> lldpNeigName = new ArrayList<String>();
    public static ArrayList<String> lldpNeigInt = new ArrayList<String>();
    public static ArrayList<String> lldpNeigMac = new ArrayList<String>();
    public static ArrayList<String> deviceModel = new ArrayList<String>();


    public static void main() {

        System.out.println("LLDP GELDIIIII");

        frame1 out = new frame1();
        String testWalk="";

        String satir[]=null;
        String esit[]=null;
        String hostInt = null;
        for(int i=0; i<out.ipler.size();i++)
        {
            try {

                devicePid = SNMPManager.main("udp:"+out.ipler.get(i).toString()+"/161","1.0.8802.1.1.2.1.5.4795.1.2.7.0");

            if(!devicePid.startsWith("no"))
            {
                // To determine node count and Id s

                snmpCheck= SNMPManager.main("udp:"+out.ipler.get(i).toString()+"/161","1.3.6.1.2.1.1.5.0");
                deviceModel.add(devicePid);
                topologyNodeId.add(snmpCheck);



            testWalk =  t1.main(out.ipler.get(i).toString(),LLDP_OID);


            satir= testWalk.split("\n");
            //System.out.println("satir 0"+satir[0].toString());
            //System.out.println("satir 1"+satir[1].toString());
            int ind =0;
            for(int k=0;k<satir.length;k++)
            {

                esit = null;
                esit = satir[k].split("=");
                //System.out.println("===Hostlar");
                //System.out.println("ind 0: "+esit[ind]);
                if(esit[ind].startsWith("1.0.8802.1.1.2.1.4.1.1.7.0") && !esit[ind].equals("1.0.8802.1.1.2.1.4.1.1.7.0.1.2 "))
                {


                    hostInt = esit[ind].substring(esit[ind].length()-5, esit[ind].length()-3);
                    //System.out.println("===Start-4.1.1.7.0 - genel cnt: "+ arrayCnts +" fa0-"+hostInt);
                    if(!hostInt.startsWith("."))
                    {
                        //System.out.println("===Start-4.1.1.7.0 - .li cnt: " + arrayCnts +"fa0-"+hostInt);
                        lldpHostInt.add("fa0-"+hostInt);

                    }
                    else
                    {
                        //System.out.println("===Start-4.1.1.7.0 - .siz cnt: " + arrayCnts +"fa0-"+hostInt);
                        lldpHostInt.add("fa0-"+hostInt.substring(hostInt.length()-1,hostInt.length())); 

                    }

                    //System.out.println("=== LLDPNeigh cnt:" + arrayCnts + esit[1]);
                    lldpNeigInt.add(esit[1]);


                }
                else if(esit[ind].startsWith("1.0.8802.1.1.2.1.4.1.1.9.0"))
                {
                    //System.out.println("=== NeighNAme cnt:" + arrayCnts + esit[1]);
                    if(!esit[1].equals(" "))
                    {
                        lldpNeigName.add(esit[1]);
                        lldpHostName.add(snmpCheck);
                    }



                //  lldpHostName.add(out.asd);

                }
                else if(esit[ind].startsWith("1.0.8802.1.1.2.1.4.1.1.5.0") && !esit[ind].equals("1.0.8802.1.1.2.1.4.1.1.5.0.1.2 "))
                {

                    lldpNeigMac.add(esit[1]);
                }
            }
            }

            else   // SNMP DESTEKLEMEYEN CIHAZLAR ICIN COZUM BULUNACAK
            {


                System.out.println("*********There is unknown device here!!!! ******");

            }
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }//
        }


        System.out.println("---HostName---");
        for(int i=0; i<lldpHostName.size();i++)
        {
            System.out.println(lldpHostName.get(i).toString());
        }
        System.out.println("---HostInt---");
        for(int i=0; i<lldpHostInt.size();i++)
        {

            System.out.println(lldpHostInt.get(i).toString());

        }
        System.out.println("---NeighInt---");
        for(int i=0; i<lldpHostInt.size();i++)
        {

            System.out.println(lldpNeigInt.get(i).toString());

        }
        System.out.println("---NeighName---");
        for(int i=0; i<lldpNeigName.size();i++)
        {
            System.out.println(lldpNeigName.get(i).toString());
        }
        System.out.println("---NeighMac---");
        for(int i=0; i<lldpHostInt.size();i++)
        {
            System.out.println(lldpNeigMac.get(i).toString());
        }
        System.out.println("---NodeId---");
        for(int i=0; i<topologyNodeId.size();i++)
        {
            System.out.println(topologyNodeId.get(i).toString());
        }

        for (int i=0;i<lldpNeigName.size();i++)
        {
            if(!topologyNodeId.contains(lldpNeigName.get(i).trim()))
            {
                topologyNodeId.add(lldpNeigName.get(i));
            }
        }


        System.out.println("===LLDPNODE ID");
        for(int i=0; i<topologyNodeId.size();i++)
        {
            System.out.println(topologyNodeId.get(i).toString());
        }   




    //  createCSV();

        //WriteXMLFile.main();



    enter code here

        /*lldpHostName.clear();
        lldpHostInt.clear();
        lldpNeigInt.clear();
        lldpNeigMac.clear();
        lldpNeigName.clear();
        topologyNodeId.clear();
        deviceModel.clear();*/


    }

}
包NDMSMain;
导入java.io.IOException;
导入java.util.ArrayList;
导入snmpandler.SNMPManager;
导入snmpandler.SNMPWalk;
导入TopologyHandler.WriteXMLFile;
公共类LLDPD发现{
静态SNMPWalk t1=新的SNMPWalk();
公共静态字符串LLDP_OID=“1.0.8802.1.1.2.1.4.1.1”;
公共静态字符串snmpCheck=null;//模型
公共静态字符串devicePid=null;//产品Id
公共静态ArrayList topologyNodeId=新ArrayList();
public static ArrayList lldpHostName=new ArrayList();
public static ArrayList lldpHostInt=new ArrayList();
public static ArrayList lldpNeigName=new ArrayList();
public static ArrayList lldpNeigInt=new ArrayList();
public static ArrayList lldpNeigMac=new ArrayList();
公共静态ArrayList deviceModel=new ArrayList();
公共静态void main(){
System.out.println(“LLDP Geldii III”);
frame1 out=新frame1();
字符串testWalk=“”;
字符串satir[]=null;
字符串esit[]=null;
字符串hostInt=null;

对于(int i=0;inow),我找到了MIB树lldpObjects(1.0.8802.1.1.2.1)。里面有lldpRemoteSystemsData(1.0.8802.1.1.2.1.3),它包含当前交换机上的端口。然后我找到了lldpRemoteSystemsData(1.0.8802.1.1.2.1.4)其中包括邻居的端口和mac地址。但我的问题是找到当前交换机上的哪个端口是邻居连接的?它们是否有一个转换表,以查看当前交换机上的哪个端口连接到mac地址为xxxI的邻居交换机的端口。我也面临这个问题,我需要获得远程Ip地址,但它提供MAC地址,我们如何从LLDP MIB获取远程设备IpAddress,请帮助…谢谢回答。但我对信息不是很确定。你能给我一个例子吗?MIB 1.0.8802.1.1.2.1.4.1.1.5给我来自邻居的MAC地址,因此不知道如何获取与cu连接的端口号rrent交换机。(不是邻居)另一个问题:当我有一个设备的MAC地址时,是否有可能获得IP_地址?(注意:我只有网络中的交换机)当然。那么假设你有这个家伙:
LLDP-MIB::lldpLocPortId.4=STRING:“FastEthernet1”
。然后您还应该拥有其中一个:
IF-MIB::ifName.4=STRING:“eth1”
。您将lldpLocPortNum与ifIndex交叉引用,即上面的“4”。如果需要,我可以添加更多细节,SNMP可以是神秘的。这也适用于lldpRemLocalPortNum(其类型与LLDPPORTNER相同)所以当我看:lldpRemTable.lldpRemEntry.lldpremchassid.1325376015.2.1 ec e5 55 32 20 88时,数字.2总是给我连接到mac地址的当前交换机的端口号?你有没有像我们讨论的那样提供更多详细解释snmp的好来源?另一个问题:是否有可能获得当我有设备的MAC地址时,IP_地址?(注意:我只有网络中的交换机)是的;它们总是给你端口号。注意端口号是任意的;端口号1是谁?eth1?lo?eth_br?(看到问题了吗?)没有从2(端口号)映射到类似描述的东西(ifName=“eth2”,等等),端口号没有那么有意义。但是通过映射,它非常有用。它不能保证您可以获得IP地址;可能远程设备没有IP地址,对吗?
lldpRemTable.lldpRemEntry.lldpremchassid.1325376015.2.1 ec e5 55 32 20 88
表示远程设备的Chassid是MAC地址。但是remote可以是IP地址、MAC地址或任何其他地址(请参阅lldpRemChassisIdSubtype)。获得IP地址是一个不错的奖励,但您不能依赖它;LLDP是第2层协议,因此IP(第3层)高于其支付等级。我如何从邻居处获得IP地址?有好的解决方案获得IP地址吗?