network programming - Find Neighbour with SNMP LLDP -


i have several switches (hirschmann mach1040, rs40) connected together. want elict mac address/ip address of connected neigbour switch on port x snmp. there lldp mib_value tells me neihbour mac or ip @ specific port on swich??

thanks lot help!!!

this code walking lldp oid on devices list contains ip addres , add neighbourships parallel arrays. ex; (each heading arraylist) hostname hostinterface neigbourname neighbourint sw2960 fa0/1 hp-98765 ethernet0/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"))             {                 // determine node count , 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 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());         }          (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();*/       }  } 

Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -