Perl 十进制到 ASCII 的转换
我正在从 F5 LTM 提取 SNMP 信息,并将该信息存储在 psql 数据库中。我需要帮助将十进制格式返回的数据转换为 ASCII 字符。 以下是从 SNMP 请求返回的信息的示例:
iso.3.6.1.4.1.3375.2.2.10.2.3.1.9.10.102.111.114.119.97.114.100.95.118.115 = Counter64: 0
在我的脚本中,我需要识别此信息的不同部分:
my ($prefix, $num, $char-len, $vs) = ($oid =~ /($vsTable)\.(\d+)\.(\d+)\.(.+)/);
这给出了以下内容:
(prefix= .1.3.6.1.4.1.3375.2.2.10.2.3.1)
(num= 9 )
(char-len= 10 )
(vs= 102.111.114.119.97.114.100.95.118.115)
变量 $vs
是 中的对象名称十进制格式。我想将其转换为 ASCII 字符(应该是“forward_vs”)。 有人对如何做到这一点有建议吗?
I am pulling SNMP information from an F5 LTM, and storing this information in a psql database. I need help converting the returned data in decimal format into ASCII characters.
Here is an example of the information returned from the SNMP request:
iso.3.6.1.4.1.3375.2.2.10.2.3.1.9.10.102.111.114.119.97.114.100.95.118.115 = Counter64: 0
In my script, I need to identify the different sections of this information:
my ($prefix, $num, $char-len, $vs) = ($oid =~ /($vsTable)\.(\d+)\.(\d+)\.(.+)/);
This gives me the following:
(prefix= .1.3.6.1.4.1.3375.2.2.10.2.3.1)
(num= 9 )
(char-len= 10 )
(vs= 102.111.114.119.97.114.100.95.118.115)
The variable $vs
is the Object name in decimal format. I would like to convert this to ASCII characters (which should be "forward_vs").
Does anyone have a suggestion on how to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
鉴于这与解释 SNMP 数据有关,对我来说使用一个或多个 SNMP 模块可从 CPAN 获得。您必须对 SNMP 了解很多,才能确定您引用的字符串何时停止作为标识符(前缀)并开始作为值。与手工编写的代码相比,使用 SNMP 代码更有可能获得通用解决方案。
Given that this is related to interpreting SNMP data, it seems logical to me to use one or more of the SNMP modules available from CPAN. You have to know quite a lot about SNMP to determine when the string you quote stops being the identifier (prefix) and starts to be the value. You have a better chance of getting a general solution with SNMP code than with hand-hacked code.
Jonathan Leffler 有正确的答案,但这里有一些事情可以扩展您的 Perl 视野:
执行,打印:
一旦您清楚了两者,您可以按空格键继续或按 q 退出。 :)
编辑:最后一个也可以写,
但请不要。 :)
Jonathan Leffler has the right answer, but here are a couple of things to expand your Perl horizons:
Executed, that prints:
Once both are clear to you, you may hit space to continue or q to quit. :)
EDIT: The last one can also be written
But please don't. :)
简单的解决方案:
Simple solution:
例如,
For example,