http://www.itmanage.info/technology/router/syslog/kiwi_syslog_server.html
Function Main()
Dim objShell, MsgTxt, MsgHostAddress
Set objShell = CreateObject("WScript.Shell")
MsgTxt = Fields.VarRawMessageText
MsgHostAddress = Fields.VarPeerAddress
objShell.sendkeys MsgHostAddress & vbtab & MsgTxt
objShell.sendkeys "{ENTER}"
End Function
#!/usr/bin/php
<?php
$res = shell_exec("./do1.sh $argv[1]");
shell_exec("./do1.sh $argv[1] > output1.txt");
$ex = explode("Port ID",$res);
$res = trim($ex[1]);
$ex = explode("\n",$res);
function getip($interface,$hostname) {
global $argv;
$hostname = explode(".",$hostname);
$hostname = $hostname[0];
$do2 = "#!/usr/bin/expect\n";
$do2 .= "set ip [lrange \$argv 0 0]\r\n";
$do2 .= "spawn telnet \${ip}\r\n";
$do2 .= "expect \"Username:\"\r\n";
$do2 .= "send \"xxx\\n\"\r\n";
$do2 .= "expect \"Password:\"\r\n";
$do2 .= "send \"yyy\\n\"\r\n";
$do2 .= "expect \">\"\r\n";
$do2 .= "send \"enable\\n\"\r\n";
$do2 .= "expect \"Password:\"\r\n";
$do2 .= "send \"yyy\\n\"\r\n";
$do2 .= "expect \"#\"\r\n";
$do2 .= "send \"termon len 0\\n\"\r\n";
$do2 .= "expect \"#\"\r\n";
$do2 .= "send \"show cdp ne ".trim($interface)." detail\\n\"\r\n";
$do2 .= "expect \"#\"\r\n";
$do2 .= "send \"ping $hostname\\n\"\r\n";
$do2 .= "expect \"#\"\r\n";
$do2 .= "send \"quit\\n\"\r\n";
$fp = fopen("do2.sh","w+");
fwrite($fp,$do2);
fclose($fp);
shell_exec("chmod 777 ./do2.sh");
//$res = shell_exec("./do2.sh $argv[1] | grep \"IP address:\"");
shell_exec("./do2.sh $argv[1] > output2.txt");
//$ex = explode("\n",trim($res));
$res = shell_exec("cat output2.txt | grep \"ICMP \"");
$res = explode(" to ",$res);
if(count($res)>1) $res = explode(",",$res[1]);
if(trim($res[0])!="") {
return sprintf("%-16s",trim($res[0]));
} else {
$res = shell_exec("./do2.sh $argv[1] | grep \"IP address:\"");
$ex = explode("\n",trim($res));
return sprintf("%-16s",trim(str_replace("IP address: ","",$ex[0]))."*");
}
}
for($i=0; $i<count($ex)-1; $i++) {
$tmp = trim($ex[$i])."\r\n";
$ex2 = explode(" ",$tmp);
$dhost = $ex2[0];
$ex3 = explode(".",$dhost);
//if(strlen($ex2[0])==17) {
//$sint = substr
//} else
if(strlen($ex2[0])>18) {
//echo trim($ex[++$i]);
$ex4 = explode(" ",trim($ex[++$i]));
$sint = trim($ex4[0])." ".trim($ex4[1]);
$dint = trim($ex4[count($ex4)-2])." ".trim($ex4[count($ex4)-1]);
} else {
$dint = trim($ex2[count($ex2)-2])." ".trim($ex2[count($ex2)-1]);
$sint = substr($tmp,17,16);
}
echo trim($sint)." \t-->\t".trim($dint)." \t".getip($sint,$dhost)." \t".trim($dhost)."\r\n";
}
//echo "=======================================\r\n";
//if($argv[2]!="") {
$res = shell_exec("./do3.sh $argv[1] | grep 10.150");
echo $res;
$res = shell_exec("./do3.sh $argv[1] | grep 10.164");
echo $res;
$res = shell_exec("./do3.sh $argv[1] | grep 10.33");
echo $res;
//}
?>
#!/usr/bin/expect
set ip [lrange $argv 0 0]
spawn telnet ${ip}
expect "Username:"
send "xxx\n"
expect "Password:"
send "yyy\n"
expect ">"
send "enable\n"
expect "Password:"
send "yyy\n"
expect "#"
send "ter len 0\n"
expect "#"
send "show cdp neighbors\n"
expect "#"
send "quit\n"
WS-X6704-10GE TBM2417IWI<br />|___WS-F6700-DFC3CXL TBM2419L2K<br />RSP720-3CXL-GE KBF2356ANZ<br />|___7600-PFC3CXL KBF2356AEV<br />|___7600-MSFC4 KBF2356ACZ<br />WS-X6724-SFP TBM2417K38<br />|___WS-F6700-DFC3CXL TBM2419L2L
#!/usr/bin/php
<?php
$res = shell_exec("./do4.sh $argv[1]");
$ex = explode("module",$res);
$showmodule = trim($ex[count($ex)-1]);
$ex = explode("\r\n\r\n",$showmodule);
$text1 = explode("\n",$ex[0]);
$text2 = explode("\n",$ex[2]);
$module = array();
$submod = array();
for($i=2; $i<count($text1); $i++) {
$module[$i-2]['mod'] = (int)substr($text1[$i],0,3);
$module[$i-2]['model'] = substr($text1[$i],49,17);
$module[$i-2]['sn'] = substr($text1[$i],68,10);
}
//echo "**********************************\n";
for($i=2; $i<count($text2); $i++) {
$submod[$i-2]['mod'] = (int)substr($text2[$i],0,3);
$submod[$i-2]['model'] = substr($text2[$i],33,16);
$submod[$i-2]['sn'] = substr($text2[$i],52,10);
}
for($i=0; $i<count($module); $i++) {
echo $module[$i]['model']."\t".$module[$i]['sn']."\n";
for($j=0; $j<count($submod); $j++) {
if($module[$i]['mod']==$submod[$j]['mod']) echo "|___".$submod[$j]['model']."\t".$submod[$j]['sn']."\n";
}
}
//echo $card;
//print_r($ex);
//echo $showmodule;
?>
#!/usr/bin/expect
set ip [lrange $argv 0 0]
spawn telnet ${ip}
expect "Username:"
send "xxx\n"
expect "Password:"
send "yyy\n"
expect ">"
send "enable\n"
expect "Password:"
send "yyy\n"
expect "#"
send "show module\n"
expect "#"
send "quit\n"
# $language = "VBScript" ' xxx.vbs<br /># $interface = "1.0"<br /><br />'==========================================================================<br />' DATE : 26/10/2010<br />' UPDATED: <br />' Thank : Brian Desmond<br />'==========================================================================<br /><br />Sub Main<br /> Const username = "plawansai" ' Username to use for login<br /> Const password = "rmutt" ' Password for corresponding user<br /> Const loginPass = "rmutt" ' Password to use for password only login (aka no aaa new-model)<br /> <br /> Const oldEnablePass = "rmutt" ' The current enable Password<br /> <br /> Const DEVICE_FILE_PATH = "C:sh inv.txt" ' สั่งให้ไปอ่าน list ip จาก File ซึ่งอยู่ folder เดียวกับตัว script<br /> <br /> Dim fso<br /> Set fso = CreateObject("Scripting.FileSystemObject")<br /> <br /> Dim fil<br /> Set fil = fso.OpenTextFile(DEVICE_FILE_PATH)<br /> <br /> Dim ip<br /> Dim name<br /> Dim protocol<br /> Dim line<br /> Dim cnxnString<br /> While Not fil.AtEndOfStream<br /> line = fil.ReadLine<br /> <br /> name = Split(line, ";")(0)<br /> ip = Split(line, ";")(1)<br /> protocol = Split(line, ";")(2)<br /> <br /> Select Case protocol<br /> Case "Telnet"<br /> cnxnString = "/TELNET " & ip & " 23"<br /> Case "SSH2"<br /> cnxnString = "/SSH2 /L " & username & " /PASSWORD " & password & " /C 3DES /M MD5 " & ip<br /> Case "SSH1"<br /> cnxnString = "/SSH1 /L " & username & " /PASSWORD " & password & " /C 3DES /M MD5 " & ip<br /> End Select <br /> <br /> 'Connect By Telnet'<br /> crt.Screen.Synchronous = True<br /> crt.Session.Connect cnxnString<br /> If protocol = "Telnet" Then<br /> 'Authentication by TACACS+'<br /> Dim index<br /> index = crt.Screen.WaitForStrings("Username:", "Password:")<br /> <br /> If index = 1 Then <br /> crt.Screen.Send username & vbCr <br /> crt.Screen.WaitForString "Password:"<br /> crt.Screen.Send password & vbCr<br /> End If<br /> End If<br /> <br /> 'Enable'<br /> crt.Screen.WaitForString ">"<br /> crt.Screen.Send "en" & vbCr <br /> crt.Screen.WaitForString "Password:"<br /> crt.Screen.Send oldEnablePass & vbCr<br /><br /> 'Privilege Mode'<br /> 'crt.Screen.WaitForString "#"<br /> 'crt.Screen.Send "conf t" & vbCr<br /> 'crt.Screen.WaitForString "(config)#"<br /><br /> '***** Command Input *****'<br /> crt.Screen.WaitForString "#" ' รอเครื่องหมาย #<br /> crt.Screen.Send "sho inv" & vbCr ' ส่ง string sho inv<br /> crt.Screen.WaitForString "#"<br /> <br /> '***** Disconnect *****'<br /> crt.Session.Disconnect <br /> Wend<br /> <br /> fil.Close <br />End Sub
;10.5.0.1;Telnet<br />;10.5.0.2;Telnet
crt.Screen.Send "conf t" & vbCr<br /> crt.Screen.WaitForString "(config)#"<br /> crt.Screen.Send "kron policy-list Backupcfg" & vbCr<br /> crt.Screen.WaitForString "(config)#"<br /> crt.Screen.Send "cli show run | redirect tftp://10.5.3.22/" & ip & ".cfg" & vbCr ' ได้ ip มาแล้วก็เอามาใช้ประโยชน์ซะ<br /> crt.Screen.WaitForString "(config)#"<br /> crt.Screen.Send "kron occurrence Backupcfg in 1:00:00 recurring" & vbCr ' ให้เก็บวันละครั้ง<br /> crt.Screen.WaitForString "(config)#"<br /> crt.Screen.Send "policy-list Backupcfg" & vbCr<br /> crt.Screen.WaitForString "(config)#"<br /> crt.Screen.Send "end" & vbCr<br /> crt.Screen.WaitForString "#"
http://www.vwin.co.th/document.php?node=5
It looks like you're new here. If you want to get involved, click one of these buttons!