Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Network device H3c get interface list oid == "1.3.6.1.2.1.2.2.1.2" #392

Open
Laurel-rao opened this issue Jan 10, 2022 · 1 comment
Open

Comments

@Laurel-rao
Copy link
Contributor

i use the method getBulk to get the interface list on the H3C device.
if i use snmpwalk tool to run this oid , it can display 50 interfaces, and use the gosnmp getBulk ,it just display 35 interfaces, i change the parameter maxRepetitions to 500 already.

@ljluestc
Copy link

import (
    "github.com/soniah/gosnmp"
    "fmt"
)

func main() {
    target := "your_device_ip"
    community := "your_community_string"
    oid := ".1.3.6.1.2.1.2.2.1.2" // Interface names OID

    gosnmp.Default.Target = target
    gosnmp.Default.Community = community

    var startIndex = 0
    var batchSize = 10 // Adjust this based on your device's capabilities

    for {
        results, err := gosnmp.Default.GetBulk(startIndex, batchSize, oid)
        if err != nil {
            fmt.Println("Error:", err)
            break
        }

        if len(results.Variables) == 0 {
            break // No more interfaces
        }

        // Process the retrieved interfaces here

        // Update the startIndex for the next batch
        startIndex = results.Variables[len(results.Variables)-1].Name
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants