自制网关切换器实例(转)

两个文件,一个是脚本,一个是配置文件.

配置文件config.ini

[setup]
name=聚友网吧
'共有线路条数
line=2

'第一条线路的设置,以下类同
[net1]
'线路名称,可自定义
name1=电信线路
'网关地址
ip1=218.5.18.1

[net2]
name2=联通线路
ip2=192.168.0.1

[net3]
name3=线路三
ip3=192.168.0.2

[net4]
name4=线路四
ip4=

[net5]
name5=线路五
ip5=

[net6]
name6=线路六
ip6=

[net7]
name7=线路七
ip7=

[net8]
name8=线路八
ip8=


脚本:

#include
$barname = iniread("config.ini","setup","name","")
Global $i
Global $line
$line = IniRead("config.ini","setup","line","")
if $line <1 or $line >8 Then
Exit
EndIf
;读取INI文件中的设置,并赋值;
Opt("TrayIconHide", 1)
$name1 = iniread("config.ini","net1","name1","")
$ip1 = iniread("config.ini","net1","ip1","")
$name2 = iniread("config.ini","net2","name2","")
$ip2 = iniread("config.ini","net2","ip2","")
$name3 = iniread("config.ini","net3","name3","")
$ip3 = iniread("config.ini","net3","ip3","")
$name4 = iniread("config.ini","net4","name4","")
$ip4 = iniread("config.ini","net4","ip4","")
$name5 = iniread("config.ini","net5","name5","")
$ip5 = iniread("config.ini","net5","ip5","")
$name6 = iniread("config.ini","net6","name6","")
$ip6 = iniread("config.ini","net6","ip6","")
$name7 = iniread("config.ini","net7","name7","")
$ip7 = iniread("config.ini","net7","ip7","")
$name8 = iniread("config.ini","net8","name8","")
$ip8 = iniread("config.ini","net8","ip8","")

if $line = 1 or $line =2 Then
$hight =100
EndIf
if $line = 3 or $line =4 Then
$hight =150
EndIf
if $line = 5 or $line = 6 Then
$hight =200
EndIf
if $line = 7 or $line = 8 Then
$hight =250
EndIf
;开始设置窗口
GUICreate($barname & "网关切换器", 260, $hight)
Opt("GUICoordMode",2)


if $line=1 Then
$bt1 = GUICtrlCreateButton ($name1, 15, 30, 100, 30)
GUISetState ()
While 1
$msg = GUIGetMsg()
Select
Case $msg = $bt1
run(@comspec & " /c route delete 0.0.0.0","",@sw_hide)
Run(@comspec & " /c route add 0.0.0.0 mask 0.0.0.0 " & $ip1,"",@sw_hide)
Case $msg = $GUI_EVENT_CLOSE
GUIDelete()
Exit
EndSelect
WEnd
ElseIf $line=2 Then
$bt1 = GUICtrlCreateButton ($name1, 15, 30, 100, 30)
$bt2 = GUICtrlCreateButton ($name2, 20, -30, 100, 30)
GUISetState ()
While 1
$msg = GUIGetMsg()
Select
Case $msg = $bt1
run(@comspec & " /c route delete 0.0.0.0","",@sw_hide)
Run(@comspec & " /c route add 0.0.0.0 mask 0.0.0.0 " & $ip1,"",@sw_hide)
Case $msg = $bt2
run(@comspec & " /c route delete 0.0.0.0","",@sw_hide)
Run(@comspec & " /c route add 0.0.0.0 mask 0.0.0.0 " & $ip2,"",@sw_hide)
Case $msg = $GUI_EVENT_CLOSE
GUIDelete()
Exit
EndSelect
WEnd

ElseIf $line=3 Then
$bt1 = GUICtrlCreateButton ($name1, 15, 30, 100, 30)
$bt2 = GUICtrlCreateButton ($name2, 20, -30, 100, 30)
$bt3 = GUICtrlCreateButton ($name3, -220, 20, 100, 30)
GUISetState ()
While 1
$msg = GUIGetMsg()
Select
Case $msg = $bt1
run(@comspec & " /c route delete 0.0.0.0","",@sw_hide)
Run(@comspec & " /c route add 0.0.0.0 mask 0.0.0.0 " & $ip1,"",@sw_hide)
Case $msg = $bt2
run(@comspec & " /c route delete 0.0.0.0","",@sw_hide)
Run(@comspec & " /c route add 0.0.0.0 mask 0.0.0.0 " & $ip2,"",@sw_hide)
Case $msg = $bt3
run(@comspec & " /c route delete 0.0.0.0","",@sw_hide);
Run(@comspec & " /c route add 0.0.0.0 mask 0.0.0.0 " & $ip3,"",@sw_hide)
Case $msg = $GUI_EVENT_CLOSE
GUIDelete()
Exit
EndSelect
WEnd

ElseIf $line=4 Then
$bt1 = GUICtrlCreateButton ($name1, 15, 30, 100, 30)
$bt2 = GUICtrlCreateButton ($name2, 20, -30, 100, 30)
$bt3 = GUICtrlCreateButton ($name3, -220, 20, 100, 30)
$bt4 = GUICtrlCreateButton ($name4, 20, -30, 100, 30)
GUISetState ()
While 1
$msg = GUIGetMsg()
Select
Case $msg = $bt1
run(@comspec & " /c route delete 0.0.0.0","",@sw_hide)
Run(@comspec & " /c route add 0.0.0.0 mask 0.0.0.0 " & $ip1,"",@sw_hide)
Case $msg = $bt2
run(@comspec & " /c route delete 0.0.0.0","",@sw_hide)
Run(@comspec & " /c route add 0.0.0.0 mask 0.0.0.0 " & $ip2,"",@sw_hide)
Case $msg = $bt3
run(@comspec & " /c route delete 0.0.0.0","",@sw_hide);
Run(@comspec & " /c route add 0.0.0.0 mask 0.0.0.0 " & $ip3,"",@sw_hide)
Case $msg = $bt4
run(@comspec & " /c route delete 0.0.0.0","",@sw_hide)
Run(@comspec & " /c route add 0.0.0.0 mask 0.0.0.0 " & $ip4,"",@sw_hide)
Case $msg = $GUI_EVENT_CLOSE
GUIDelete()
Exit
EndSelect
WEnd

ElseIf $line=5 Then
$bt1 = GUICtrlCreateButton ($name1, 15, 30, 100, 30)
$bt2 = GUICtrlCreateButton ($name2, 20, -30, 100, 30)
$bt3 = GUICtrlCreateButton ($name3, -220, 20, 100, 30)
$bt4 = GUICtrlCreateButton ($name4, 20, -30, 100, 30)
$bt5 = GUICtrlCreateButton ($name5, -220, 20, 100, 30)
GUISetState ()
While 1
$msg = GUIGetMsg()
Select
Case $msg = $bt1
run(@comspec & " /c route delete 0.0.0.0","",@sw_hide)
Run(@comspec & " /c route add 0.0.0.0 mask 0.0.0.0 " & $ip1,"",@sw_hide)
Case $msg = $bt2
run(@comspec & " /c route delete 0.0.0.0","",@sw_hide)
Run(@comspec & " /c route add 0.0.0.0 mask 0.0.0.0 " & $ip2,"",@sw_hide)
Case $msg = $bt3
run(@comspec & " /c route delete 0.0.0.0","",@sw_hide);
Run(@comspec & " /c route add 0.0.0.0 mask 0.0.0.0 " & $ip3,"",@sw_hide)
Case $msg = $bt4
run(@comspec & " /c route delete 0.0.0.0","",@sw_hide)
Run(@comspec & " /c route add 0.0.0.0 mask 0.0.0.0 " & $ip4,"",@sw_hide)
Case $msg = $bt5
run(@comspec & " /c route delete 0.0.0.0","",@sw_hide)
Run(@comspec & " /c route add 0.0.0.0 mask 0.0.0.0 " & $ip5,"",@sw_hide)
Case $msg = $GUI_EVENT_CLOSE
GUIDelete()
Exit
EndSelect
WEnd

ElseIf $line=6 Then
$bt1 = GUICtrlCreateButton ($name1, 15, 30, 100, 30)
$bt2 = GUICtrlCreateButton ($name2, 20, -30, 100, 30)
$bt3 = GUICtrlCreateButton ($name3, -220, 20, 100, 30)
$bt4 = GUICtrlCreateButton ($name4, 20, -30, 100, 30)
$bt5 = GUICtrlCreateButton ($name5, -220, 20, 100, 30)
$bt6 = GUICtrlCreateButton ($name6, 20, -30, 100, 30)
GUISetState ()
While 1
$msg = GUIGetMsg()
Select
Case $msg = $bt1
run(@comspec & " /c route delete 0.0.0.0","",@sw_hide)
Run(@comspec & " /c route add 0.0.0.0 mask 0.0.0.0 " & $ip1,"",@sw_hide)
Case $msg = $bt2
run(@comspec & " /c route delete 0.0.0.0","",@sw_hide)
Run(@comspec & " /c route add 0.0.0.0 mask 0.0.0.0 " & $ip2,"",@sw_hide)
Case $msg = $bt3
run(@comspec & " /c route delete 0.0.0.0","",@sw_hide);
Run(@comspec & " /c route add 0.0.0.0 mask 0.0.0.0 " & $ip3,"",@sw_hide)
Case $msg = $bt4
run(@comspec & " /c route delete 0.0.0.0","",@sw_hide)
Run(@comspec & " /c route add 0.0.0.0 mask 0.0.0.0 " & $ip4,"",@sw_hide)
Case $msg = $bt5
run(@comspec & " /c route delete 0.0.0.0","",@sw_hide)
Run(@comspec & " /c route add 0.0.0.0 mask 0.0.0.0 " & $ip5,"",@sw_hide)
Case $msg = $bt6
run(@comspec & " /c route delete 0.0.0.0","",@sw_hide)
Run(@comspec & " /c route add 0.0.0.0 mask 0.0.0.0 " & $ip6,"",@sw_hide)
Case $msg = $GUI_EVENT_CLOSE
GUIDelete()
Exit
EndSelect
WEnd

ElseIf $line=7 Then
$bt1 = GUICtrlCreateButton ($name1, 15, 30, 100, 30)
$bt2 = GUICtrlCreateButton ($name2, 20, -30, 100, 30)
$bt3 = GUICtrlCreateButton ($name3, -220, 20, 100, 30)
$bt4 = GUICtrlCreateButton ($name4, 20, -30, 100, 30)
$bt5 = GUICtrlCreateButton ($name5, -220, 20, 100, 30)
$bt6 = GUICtrlCreateButton ($name6, 20, -30, 100, 30)
$bt7 = GUICtrlCreateButton ($name7, -220, 20, 100, 30)
GUISetState ()
While 1
$msg = GUIGetMsg()
Select
Case $msg = $bt1
run(@comspec & " /c route delete 0.0.0.0","",@sw_hide)
Run(@comspec & " /c route add 0.0.0.0 mask 0.0.0.0 " & $ip1,"",@sw_hide)
Case $msg = $bt2
run(@comspec & " /c route delete 0.0.0.0","",@sw_hide)
Run(@comspec & " /c route add 0.0.0.0 mask 0.0.0.0 " & $ip2,"",@sw_hide)
Case $msg = $bt3
run(@comspec & " /c route delete 0.0.0.0","",@sw_hide);
Run(@comspec & " /c route add 0.0.0.0 mask 0.0.0.0 " & $ip3,"",@sw_hide)
Case $msg = $bt4
run(@comspec & " /c route delete 0.0.0.0","",@sw_hide)
Run(@comspec & " /c route add 0.0.0.0 mask 0.0.0.0 " & $ip4,"",@sw_hide)
Case $msg = $bt5
run(@comspec & " /c route delete 0.0.0.0","",@sw_hide)
Run(@comspec & " /c route add 0.0.0.0 mask 0.0.0.0 " & $ip5,"",@sw_hide)
Case $msg = $bt6
run(@comspec & " /c route delete 0.0.0.0","",@sw_hide)
Run(@comspec & " /c route add 0.0.0.0 mask 0.0.0.0 " & $ip6,"",@sw_hide)
case $msg = $bt7
run(@comspec & " /c route delete 0.0.0.0","",@sw_hide)
Run(@comspec & " /c route add 0.0.0.0 mask 0.0.0.0 " & $ip7,"",@sw_hide)
Case $msg = $GUI_EVENT_CLOSE
GUIDelete()
Exit
EndSelect
WEnd

ElseIf $line=8 Then
$bt1 = GUICtrlCreateButton ($name1, 15, 30, 100, 30)
$bt2 = GUICtrlCreateButton ($name2, 20, -30, 100, 30)
$bt3 = GUICtrlCreateButton ($name3, -220, 20, 100, 30)
$bt4 = GUICtrlCreateButton ($name4, 20, -30, 100, 30)
$bt5 = GUICtrlCreateButton ($name5, -220, 20, 100, 30)
$bt6 = GUICtrlCreateButton ($name6, 20, -30, 100, 30)
$bt7 = GUICtrlCreateButton ($name7, -220, 20, 100, 30)
$bt8 = GUICtrlCreateButton ($name8, 20, -30, 100, 30)
GUISetState ()
While 1
$msg = GUIGetMsg()
Select
Case $msg = $bt1
run(@comspec & " /c route delete 0.0.0.0","",@sw_hide)
Run(@comspec & " /c route add 0.0.0.0 mask 0.0.0.0 " & $ip1,"",@sw_hide)
Case $msg = $bt2
run(@comspec & " /c route delete 0.0.0.0","",@sw_hide)
Run(@comspec & " /c route add 0.0.0.0 mask 0.0.0.0 " & $ip2,"",@sw_hide)
Case $msg = $bt3
run(@comspec & " /c route delete 0.0.0.0","",@sw_hide);
Run(@comspec & " /c route add 0.0.0.0 mask 0.0.0.0 " & $ip3,"",@sw_hide)
Case $msg = $bt4
run(@comspec & " /c route delete 0.0.0.0","",@sw_hide)
Run(@comspec & " /c route add 0.0.0.0 mask 0.0.0.0 " & $ip4,"",@sw_hide)
Case $msg = $bt5
run(@comspec & " /c route delete 0.0.0.0","",@sw_hide)
Run(@comspec & " /c route add 0.0.0.0 mask 0.0.0.0 " & $ip5,"",@sw_hide)
Case $msg = $bt6
run(@comspec & " /c route delete 0.0.0.0","",@sw_hide)
Run(@comspec & " /c route add 0.0.0.0 mask 0.0.0.0 " & $ip6,"",@sw_hide)
case $msg = $bt7
run(@comspec & " /c route delete 0.0.0.0","",@sw_hide)
Run(@comspec & " /c route add 0.0.0.0 mask 0.0.0.0 " & $ip7,"",@sw_hide)
Case $msg = $bt8
run(@comspec & " /c route delete 0.0.0.0","",@sw_hide)
Run(@comspec & " /c route add 0.0.0.0 mask 0.0.0.0 " & $ip8,"",@sw_hide)
Case $msg = $GUI_EVENT_CLOSE
GUIDelete()
Exit
EndSelect
WEnd
EndIf


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10294527/viewspace-123445/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/10294527/viewspace-123445/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值