Jump to content

SNMP String


Recommended Posts

Hi @ all!

At first, sorry my English is not really good.

I´m writing a skript how i can read some snmp informations from a device.

At the moment i get the snmp informations back in hex.

$cmd="0x303102010004067075626C6963A22402046E2504570201000201003016301406082B0601020101010004084945532

D35303030"

so i make $cmd=StringRight ($cmd,16)

now I´m convert this new string into ascii $cmd="4945532D35303030"

But if the informations change i get a wrong output.

can anybody help me, please

Thanks a lot

Magicmercury

Link to comment
Share on other sites

Hi @ all!

At first, sorry my English is not really good.

I´m writing a skript how i can read some snmp informations from a device.

At the moment i get the snmp informations back in hex.

$cmd="0x303102010004067075626C6963A22402046E2504570201000201003016301406082B0601020101010004084945532

D35303030"

so i make $cmd=StringRight ($cmd,16)

now I´m convert this new string into ascii $cmd="4945532D35303030"

But if the informations change i get a wrong output.

can anybody help me, please

Thanks a lot

Magicmercury

How does "the informations change"?

What was the wrong output?

What would have been the right output?

Is the data received actually a hex string, or a long binary?

Can you show any code you used to work with this string/binary?

muttley

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

How does "the informations change"?

What was the wrong output?

What would have been the right output?

Is the data received actually a hex string, or a long binary?

Can you show any code you used to work with this string/binary?

muttley

#include <string.au3>

Dim $IP_ADDRESS,$valve
$IP_ADDRESS = "172.22.126.78"
$PORT = "161"
$STRING = "0x302902010004067075626c6963a01c02046e250457020100020100300e300c06082b060102010101000500"
$result=getsnmp($IP_ADDRESS,$STRING)
MsgBox(1,"IP Address : " &$IP_ADDRESS,"System: " & $result)


Func getsnmp($IP_ADDRESS,$CMD)
UDPStartUp()
$Start = 1
$Socket = UDPopen($IP_ADDRESS, $Port)
UDPSend($Socket, $CMD)
While (1)
$srcv = UDPRecv($Socket, 2048)
If ($srcv <> "") Then
    $stringtrim=StringRight ($srcv,16)
For $i=1 to StringLen($stringtrim)
    $num=StringMid($stringtrim,$i,2)
    $valve=$valve & Chr(Dec($num))
    $i=$i+1
Next

Return $valve
ExitLoop

EndIf
sleep(100)
WEnd
UDPCloseSocket($Socket)
UDPShutdown()
EndFunc

With the IP .78 the output is: IES-5000

Now I connect to an other IP and the output is: S-1248-51 because i said that StringRight ($srcv,16). If I change 16 to 20 the output is right, but only by this IP.

Thanks

Magicmercury

Link to comment
Share on other sites

What OID are you trying to read?

What device are you connecting to?

Are you sure the 2nd device you connect to is the same model/type as the first one? (for different models the OID are different, unless that OID is not device-specific)

If that OID is allowed to be changed by user via SNMP then the content might be different.

Alot of questions here - without an answer to them I'm affraid that you won't get much help.

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

What OID are you trying to read?

What device are you connecting to?

Are you sure the 2nd device you connect to is the same model/type as the first one? (for different models the OID are different, unless that OID is not device-specific)

If that OID is allowed to be changed by user via SNMP then the content might be different.

Alot of questions here - without an answer to them I'm affraid that you won't get much help.

Yes I need help. But I think my problem isn´t the OID. My Problem is that i can´t read the udp string.

The devices are DSLAMs they have the same OID but different Device Names.

OID: .1.3.6.1.2.1.1.1.0 - sysDescr.0 - RFC1213-MIB

Is it possible to read the udp get-response string value in a variable? I´ve attached a packet screenshot.

I hope this information help you.

post-14857-1216797419_thumb.png

Link to comment
Share on other sites

Credit to ptrex for the following script:

$objLocator = ObjCreate("WbemScripting.SWbemLocator")
$objServices = $objLocator.connectServer("", "root/snmp/localhost")

$objNamedValueSet= ObjCreate("WbemScripting.SWbemNamedValueSet")

$objNamedValueSet.Add ("AgentAddress", "Your device IP here ...")
$objNamedValueSet.Add ("AgentReadCommunityName", "public")
$objNamedValueSet.Add ("AgentWriteCommunityName", "private")

$class = "SNMP_RFC1213_MIB_system"      ;you need to change the class in order to get different OID sets

$objSet = $objServices.instancesof( $class,Default,$objNamedValueSet)

for $obj in $objset
    ConsoleWrite ( "-----------------------------" & @CRLF)
    for $prop in $obj.properties_
        ConsoleWrite ( $prop.name & " : " & $prop.value & @CRLF)
    next
next

in this post #411897

The script works (I've tested it couple minutes ago) and you can see that you can easily put the output in a variable and play with that variable later.

Hope this helps,

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...