基于SNMP网络设备监控系统的实现

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

SNMP

SDK 80 6.5 23

SNMP

SNMP

SNMP OSI 1988 Internet IAB SNMP Internet 1992 SNMPv2 SNMPv1 SNMPv3 SNMP SNMP

SNMP MIB SMI SNMP SNMP ( Hub )

SNMP

OSI (packets) SNMP UDP( ) SNMP UDP (datagrams) UDP UDP SNMP SNMP PDU(Protocol Data Unit) SNMP SNMP SNMP Version1 Version2 Version3 SNMP "public" SNMP

1. Get_Request Manager Agent

2. Get_ Next_Request Manager Agent Get-Request

3. Get_Response Agent Manager

4. Set_Request Manager Agent Agent

/ )

5. Trap Agent Agent Manager SNMP4J

SNMP4J SNMP API for Java JAVASE 1.4

/ JavaDoc wiki

Java Demo

/** * @Title SNMPTest.java * @Description TODO( ) * @Author yzh yingzh@ * @Date 05.30.2016 */public class SNMPTest { // private String address = "115.236.68.58"; /** * */ private String protocol = "udp"; /** * 1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16Java

*/ private int port = 161; /** * */ private String community = "compublik"; /** * */ private long timeout = 5 * 1000L ; /** * */ private int retry = 3; /** * SNMPv2 * * @throws IOException */ @Test public void getRequest () throws IOException { //DefaultUdpTransportMapping SNMP UDP . TransportMapping transport = new DefaultUdpTransportMapping (); // SNMPv3 Snmp snmpClient = new Snmp (transport ); // transport .listen (); // Address address = GenericAddress .parse (this .protocol + ":" + this .address + "/" + this .port ); // target Target target = new CommunityTarget (address , new OctetString (this .community )); // target .setVersion (SnmpConstants .version2c ); // target .setRetries (this .retry ); // target .setTimeout (this .timeout ); PDU request = new PDU (); // request .setType (PDU .GET ); // add OID request .add (new VariableBinding (new OID (".1.3.6.1.2.1.1.5.0"))); //

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

ResponseEvent respEvent = snmpClient .send (request , target ); PDU response = respEvent .getResponse (); if (null !=response ){ if (response .size ()>0){ VariableBinding vb = response .get (0); System .out .println ("OID: "+vb .getOid ().toString ()); System .out .println ("Value: "+vb .getVariable ().toString ()); } } }}

65

66

67

68

69

70

71

72

73

74

75

76

相关文档
最新文档