通过pysnmp获得网卡的MAC地址,如何正确显示?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

通过pysnmp获得网卡的MAC地址,如何正确显示?

jun yang-3
我的代码,如下:

#!
from pysnmp import role, v2c, asn1
import set_env
import os

req = v2c.GETREQUEST()
req['encoded_oids'] = [ asn1.OBJECTID().encode('.1.3.6.1.2.1.2.2.1.6.2') ]
tr = role.manager (('localhost', 161))
(rawrsp, src) = tr.send_and_receive(req.encode())
rsp = v2c.RESPONSE()
rsp.decode(rawrsp)
oids = map(lambda x:x[0], map(asn1.OBJECTID().decode, rsp['encoded_oids']))
print oids
vals = map(lambda x: x[0](), map(asn1.decode, rsp['encoded_vals']))
print vals


结果:
['\x00\x0c)I\xf7\xa0']

如何显示成:0:c:29:49:f7:a0 这样的格式?



_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese
Reply | Threaded
Open this post in threaded view
|

Re: 通过pysnmp获得网卡的MAC地址,如何正确显示?

Andelf
':'.join('%2x' % ord(c) for c in  ipstring1[0])    未测试

On 1/8/08, jun yang <[hidden email]> wrote:

> 我的代码,如下:
>
> #!
> from pysnmp import role, v2c, asn1
> import set_env
> import os
>
> req = v2c.GETREQUEST()
> req['encoded_oids'] = [ asn1.OBJECTID().encode('.1.3.6.1.2.1.2.2.1.6.2') ]
> tr = role.manager(('localhost', 161))
> (rawrsp, src) = tr.send_and_receive(req.encode())
> rsp = v2c.RESPONSE()
> rsp.decode(rawrsp)
> oids = map(lambda x:x[0], map(asn1.OBJECTID().decode, rsp['encoded_oids']))
> print oids
> vals = map(lambda x: x[0](), map(asn1.decode, rsp['encoded_vals']))
> print vals
>
>
> 结果:
> ['\x00\x0c)I\xf7\xa0']
>
> 如何显示成:0:c:29:49:f7:a0 这样的格式?
>
_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese
Reply | Threaded
Open this post in threaded view
|

Re: 通过pysnmp获得网卡的MAC地址,如何正确显示?

Andelf
In reply to this post by jun yang-3
hex(ord(c))?貌似也可

On 1/8/08, jun yang <[hidden email]> wrote:

> 我的代码,如下:
>
> #!
> from pysnmp import role, v2c, asn1
> import set_env
> import os
>
> req = v2c.GETREQUEST()
> req['encoded_oids'] = [ asn1.OBJECTID().encode('.1.3.6.1.2.1.2.2.1.6.2') ]
> tr = role.manager(('localhost', 161))
> (rawrsp, src) = tr.send_and_receive(req.encode())
> rsp = v2c.RESPONSE()
> rsp.decode(rawrsp)
> oids = map(lambda x:x[0], map(asn1.OBJECTID().decode, rsp['encoded_oids']))
> print oids
> vals = map(lambda x: x[0](), map(asn1.decode, rsp['encoded_vals']))
> print vals
>
>
> 结果:
> ['\x00\x0c)I\xf7\xa0']
>
> 如何显示成:0:c:29:49:f7:a0 这样的格式?
>
_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese