Advertisement
chatchai_j

oas-client.exp

Jun 30th, 2011
660
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
TCL 3.20 KB | None | 0 0
  1. #!/usr/bin/expect
  2. # updated by WIPAT 2554-06-10
  3. # get esw.oas.psu.ac.th
  4.  
  5. set ROUTER "x.x.x.x"
  6. set USER "xxxx"
  7. set PASSWORD "xxxx"
  8. set PROMPT "gsw-oas>"
  9. set WAIT_SECONDS 60
  10.  
  11. set NETWORK1 "192.168.159.0/24"
  12. set NETWORK2 "192.168.160.0/24"
  13. set NETWORK3 "192.168.161.0/24"
  14. set NETWORK4 "192.168.178.0/24"
  15.  
  16. set MYSCRIPT1 "/etc/mrtg/oas-client-exp1.sh"
  17. set MYSCRIPT2 "/etc/mrtg/oas-client-exp2.sh"
  18. set MYSCRIPT3 "/etc/mrtg/oas-client-exp3.sh"
  19. set MYSCRIPT4 "/etc/mrtg/oas-client-exp4.sh"
  20.  
  21. set MYTEMP [timestamp]
  22. set TEMP1 "/tmp/get-esw-oas-client1.temp1.$MYTEMP"
  23. set TEMP2 "/tmp/get-esw-oas-client2.temp1.$MYTEMP"
  24. set TEMP3 "/tmp/get-esw-oas-client3.temp1.$MYTEMP"
  25. set TEMP4 "/tmp/get-esw-oas-client4.temp1.$MYTEMP"
  26.  
  27. set MYFILE1 [open $TEMP1 w]
  28. spawn telnet $ROUTER
  29.  
  30. match_max 100000
  31. expect "Password:"
  32. send "$PASSWORD\r"
  33. expect "$PROMPT"
  34.  
  35. while 1 {
  36.     system "nmap -n -sP --unprivileged $NETWORK1 > /dev/null"
  37.     send "show ip arp vlan2\r"
  38.     expect {
  39.         "More--" {
  40.             puts $MYFILE1 $expect_out(buffer); send " " ; exp_continue
  41.         }
  42.         "$PROMPT" {
  43.             puts $MYFILE1 $expect_out(buffer); close $MYFILE1;
  44.             system "bash $MYSCRIPT1 $TEMP1";
  45.             set MYFILE2 [open $TEMP2 w];
  46.             system "nmap -n -sP --unprivileged $NETWORK2> /dev/null";
  47.             send "show ip arp vlan3\r";
  48.             expect {
  49.                 "More--" {
  50.                     puts $MYFILE2 $expect_out(buffer); send " " ; exp_continue
  51.                 }
  52.                 "$PROMPT" {
  53.                     puts $MYFILE2 $expect_out(buffer); close $MYFILE2;
  54.                     system "bash $MYSCRIPT3 $TEMP2";
  55.  
  56.                     set MYFILE3 [open $TEMP3 w];
  57.  
  58.                     system "nmap -n -sP --unprivileged $NETWORK3> /dev/null";
  59.                     send "show ip arp vlan4\r";
  60.                     expect {
  61.                         "More--" {
  62.                             puts $MYFILE3 $expect_out(buffer); send " " ; exp_continue
  63.                         }
  64.                         "$PROMPT" {
  65.                             puts $MYFILE3 $expect_out(buffer); close $MYFILE2;
  66.                             system "bash $MYSCRIPT3 $TEMP3";
  67.  
  68.                             set MYFILE4 [open $TEMP4 w];
  69.  
  70.                             system "nmap -n -sP --unprivileged $NETWORK4> /dev/null";
  71.                             send "show ip arp vlan5\r";
  72.                             expect {
  73.                                 "More--" {
  74.                                     puts $MYFILE4 $expect_out(buffer); send " " ; exp_continue
  75.                                 }
  76.                                 "$PROMPT" {
  77.                                     puts $MYFILE4 $expect_out(buffer); close $MYFILE4;
  78.                                     system "bash $MYSCRIPT4 $TEMP4";
  79.                                     sleep $WAIT_SECONDS; set MYFILE1 [open $TEMP1 w]
  80.                                     system "nmap -n -sP --unprivileged $NETWORK1> /dev/null";
  81.                                     send "show ip arp vlan4\r";
  82.                                 }
  83.                             }
  84.                         }
  85.                     }
  86.                 }
  87.             }
  88.         }
  89.         exp_continue
  90.     }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement