#!/usr/bin/python import pexpect import sys pobj = pexpect.spawn("ssh root@192.168.128.1") #pobj.logfile = open("enlog.txt", "a+") pobj.expect(".*password:.*") pobj.sendline(strpass) pobj.expect(".*#.*") pobj.sendline('nvram set rc_firewall="insmod ipt_mark') pobj.sendline('insmod xt_mark') pobj.sendline('iptables -t mangle -A PREROUTING -i ! `get_wanface` -d `nvram get wan_ipaddr` -j MARK --set-mark 0xd001') pobj.sendline('iptables -t nat -A POSTROUTING -m mark --mark 0xd001 -j MASQUERADE"') pobj.expect(".*#.*") pobj.sendline("nvram commit") pobj.expect(".*#.*") pobj.sendline("startservice firewall") pobj.expect(".*#.*") pobj.close()