#!/usr/bin/expect
# 定义函数:读取文件并逐行处理
proc process_file {filename} {
# 检查文件是否存在
if {!} {
puts "Error: File $filename does not exist."
return
}
# 打开文件进行读取
set fp [open$filename r]
# 逐行读取文件内容
while {[gets $fp line] !=-1} {
# 去除行首尾的空格
set line [string trim $line]
# 跳过空行
if {$line eq ""} {
continue
}
send "network host address $line n"
# expect eof
}
# 关闭文件
close $fp
}
# 主程序逻辑
if {[llength $argv] <1} {
puts "Usage: $argv0 <file_to_process>"
exit 1
}
# 获取命令行参数中的文件名
set filename [lindex $argv0]
spawn ssh test@192.168.1.1
expect "*password*"
send "testpasswordtestn"
expect "*M80X0-D*"
send "sysn"
expect "*]"
send "object-group ip address HW2024n"
send "n"
send "n"
send "n"
# 调用函数处理文件
process_file $filename
send "n"
send "n"
send "n"
send "quitn"
send "quitn"
send "quitn"
$ ./deny.exp ip.txt
原文始发于微信公众号(生有可恋):H3C 防火墙批量封IP
免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉。
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论