使用Perl从Cisco Call Manager获取IP地址列表

use*_*715 6 perl snmp cucm cisco-axl

我需要从Cisco Unified Call Manager中检索手机的IP地址列表,我希望能够尽可能地使用Perl和标准模块.

我可以使用snmpwalk获取地址(我们使用的是SNMP v3),但出于某种原因,当我使用现有代码尝试通过SNMP或Net :: SNMP执行相同操作时,我得到的最多的是一个IP地址.我似乎无法让任何一个人给我完整的清单.

这是我的snmpwalk命令:

snmpwalk -v3 -u <user> -A <password> -l authNoPriv -a SHA <ip address> 1.3.6.1.4.1.9.9.156.1.2.1.1.6
Run Code Online (Sandbox Code Playgroud)

我也得到了电话描述字段(156.1.2.1.1.4)并将这两个字段合并到一个文本文件中,这样我就可以使用它们使用LWP查询电话本身.

能够将这两个功能组合到一个脚本中以获取IP地址并查询手机的特定细节将会很棒.

有没有人有这样做的代码?

编辑:

snmpwalk返回(一大堆这些):

SNMPv2-SMI::enterprises.9.9.156.1.2.1.1.6.100 = IpAddress: xxx.xxx.xxx.xxx
Run Code Online (Sandbox Code Playgroud)

我的Perl代码返回一个IP地址(我必须重新键入它,因为它在没有Internet访问的封闭网络上):

use SNMP;

my $ccmip = "xxx.xxx.xxx.xxx";
my $user = "<username>";
my $pass = "<password>";

$sess = new SNMP::Session(DestHost => $ccmip, SecName => $user, SecLevel => 'authnoPriv', AuthPass => $pass, AuthProto => 'SHA', PrivProto => 'AES', PrivPass => $pass, Version => 3);

my $vars = new SNMP::VarList(['1.3.6.1.4.1.9.9.156.1.2.1.1.6']);
my @values = $sess->getnext($vars);

my @table = ();
while ((!$sess->{ErrorStr})) {
   push(@table, $values[0]);
   @values = $sess->getnext($vars);
}
Run Code Online (Sandbox Code Playgroud)

小智 1

您可以使用curl 执行此操作并发送XML 来查询risdb,因为只有注册的电话才会有IP 地址:

curl -s -k -u axluser:${AXLPASSWORD} -H 'Content-type: text/xml;' -H 'SOAPAction: "CUCM:DB ver=8.0"' -d @ris_reg.xml https://x.x.x.x:8443/realtimeservice/services/RisPort | xmllint --format - > ris_reg_8.log
Run Code Online (Sandbox Code Playgroud)

看:

ris_reg.xml:<?xml version="1.0" encoding="utf-8"?> <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"  xmlns:xsd="http://www.w3.org/2001/XMLSchema"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">   <soapenv:Body>
    <ns1:SelectCmDevice soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"  xmlns:ns1="http://schemas.cisco.com/ast/soap/">
      <StateInfo xsi:type="xsd:string"/>
      <CmSelectionCriteria href="#id0"/>
    </ns1:SelectCmDevice>
    <multiRef id="id0" soapenc:root="0"  soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"  xsi:type="ns2:CmSelectionCriteria"  xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"  xmlns:ns2="http://schemas.cisco.com/ast/soap/">
      <MaxReturnedDevices xsi:type="xsd:unsignedInt">0</MaxReturnedDevices>
      <Class xsi:type="xsd:string">Phone</Class>
      <Model xsi:type="xsd:unsignedInt">503</Model>
      <Status xsi:type="xsd:string">Registered</Status>
      <NodeName xsi:type="xsd:string" xsi:nil="true"/>
      <SelectBy xsi:type="xsd:string">Name</SelectBy>
      <SelectItems soapenc:arrayType="ns2:SelectItem[1]" xsi:type="soapenc:Array">
        <item href="#id1"/>
      </SelectItems>
    </multiRef>
    <multiRef id="id1" soapenc:root="0"  soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"  xsi:type="ns3:SelectItem" xmlns:ns3="http://schemas.cisco.com/ast/soap/"  xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
      <Item xsi:type="xsd:string">*</Item>
    </multiRef>   </soapenv:Body> </soapenv:Envelope>
Run Code Online (Sandbox Code Playgroud)