找回密码
 加入
搜索
查看: 2431|回复: 4

求改网关的方法

[复制链接]
发表于 2008-8-21 21:35:06 | 显示全部楼层 |阅读模式
我看这个“全自动改机名、IP、CS”的代码很长。
我只想要一段改网关代码就行了,不要用netsh来改的。

[ 本帖最后由 lotsunhim 于 2008-8-22 17:20 编辑 ]
发表于 2008-8-21 22:12:42 | 显示全部楼层
网上有个零网关切换工具
#NoTrayIcon

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <process.au3>
#include <Constants.au3>
#include <array.au3>
#include <GuiTab.au3>
#include <File.au3>

$g_szVersion = "IpChange" 
If WinExists($g_szVersion) Then Exit
AutoItWinSetTitle($g_szVersion)

$ipfile = @TempDir & "\ip.txt" 
If FileExists(@TempDir & "\ip.txt") Then FileDelete(@TempDir & "\ip.txt")
RunWait(@ComSpec & " /c route print > " & $ipfile, "", @SW_HIDE)
$file = FileOpen($ipfile, 0)
$i = 1
Do
    $Gatewaydq = FileReadLine($file, $i)
    If @error = -1 Then ExitLoop
    If StringInStr($Gatewaydq, "Default Gateway") = 0 Then
        $i = $i + 1
        $Gateway = ""
    Else
        $line1 = $i
        $Gateway = StringTrimLeft(FileReadLine($file, $i), 18)
        ExitLoop
    EndIf
Until $i = 0
FileClose($file)
FileDelete($file)

;配置脚本检测
If Not FileExists(@ScriptDir & "\Proxy.ini") Then
    MsgBox(64, "提示:", "未找到线路切换配置文件", 5)  ;检查配置文件是否存在。
    IniWrite(@ScriptDir & "\Proxy.ini", "Proxy", "示例格式", "192.168.1.1")
    IniWrite(@ScriptDir & "\Proxy.ini", "Proxy", "线路二", "192.168.1.2")
    ShellExecute("Notepad.exe", "Proxy.ini", @ScriptDir)
    Exit
EndIf
If FileExists(@ScriptDir & "\Proxy.ini") Then
    $Proxyfile = @ScriptDir & "\Proxy.ini" 
    $ProxyName = IniReadSection($Proxyfile, "Proxy")
    If @error Then
        MsgBox(4096, "", "发生错误,可能配置文件为非标准的配置文件.")
    Else
        For $p = 1 To $ProxyName[0][0]
            ;$Pno=$ProxyName[0][0]
            ;MsgBox(4096, "", "关键字:" & $ProxyName[$p][0] & @CRLF & "数值:" & $ProxyName[$p][1] & @crlf & "行数:"& $Pno)
        Next
    EndIf

EndIf

#Region ### START Koda GUI section ### Form=E:\AU3脚本程序\网关切换.kxf
$Form1 = GUICreate("零点技术联盟网络宽带线路切换工具V1.0", 378, 210, -1, -1, BitOR($WS_SYSMENU, $WS_CAPTION, $WS_POPUP, $WS_POPUPWINDOW, $WS_BORDER, $WS_CLIPSIBLINGS))
$Group1 = GUICtrlCreateGroup("", 1, -5, 377, 215)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKRIGHT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM + $GUI_DOCKHCENTER + $GUI_DOCKVCENTER + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT)
$Group2 = GUICtrlCreateGroup("", 3, 2, 373, 65)
$Label1 = GUICtrlCreateLabel("注意:由于本工具采用了即时生效功能,所以在进行", 80, 25, 280, 17)
$Label2 = GUICtrlCreateLabel("网关地址切换时,上网会有延迟,这属正常现象。", 56, 41, 268, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Label3 = GUICtrlCreateLabel("当前网关:", 72, 136, 65, 17)
GUICtrlSetFont(-1, 10, 400, 0, "宋体")
GUICtrlSetColor($Label3, 0xFF0000)
$Label4 = GUICtrlCreateLabel($Gateway, 130, 136, 120, 17)
$ip = GUICtrlCreateCombo($ProxyName[1][1], 230, 136, 120, 17)
GUICtrlSetState(-1, $GUI_HIDE)
GUICtrlSetFont(-1, 10, 400, 0, "宋体")
GUICtrlSetColor($Label4, 0xFF0000)
$Label5 = GUICtrlCreateLabel("请在列表框中选择相应的上网线路:", 72, 80, 196, 17)
$name = GUICtrlCreateCombo($ProxyName[1][0], 120, 104, 145, 25)
$url = GUICtrlCreateLabel("网址:HTTP://Www.BiosClub.Com", 8, 176, 177, 17)
$Change = GUICtrlCreateButton("确定(&O)", 192, 168, 75, 25, 0)
$cancel = GUICtrlCreateButton("取消(&C)", 280, 168, 75, 25, 0)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlSetState(-1, $GUI_HIDE)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


$Proxyfile1 = @ScriptDir & "\Proxy.ini" 
$ProxyName1 = IniReadSection($Proxyfile1, "Proxy")
If @error Then
    MsgBox(4096, "", "发生错误,可能配置文件为非标准的配置文件.")
Else
    For $pp = 1 To $ProxyName1[0][0]
        $varProxyName = GUICtrlSetData($name, $ProxyName1[$pp][0])
        $varProxyIP = GUICtrlSetData($ip, $ProxyName1[$pp][1])
        ;MsgBox(4096, "", "关键字:" & $ProxyName[$p][0] & @CRLF & "数值:" & $ProxyName[$p][1] & @crlf & "行数:"& $Pno)
    Next
EndIf

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $Form1, "int", 500, "long", 0x00090000)
            Exit
        Case $name
            $Proxyfile1 = @ScriptDir & "\Proxy.ini" 
            $ProxyName1 = IniReadSection($Proxyfile1, "Proxy")
            For $pp = 1 To $ProxyName1[0][0]
                $getname = GUICtrlRead($name)
                If $getname = $ProxyName1[$pp][0] Then GUICtrlSetData($ip, $ProxyName1[$pp][1])
                $getip = GUICtrlRead($ip)
            Next
        Case $url
            ShellExecute("iexplore.exe", "http://www.biosclub.com")
        Case $Change
            $getip = GUICtrlRead($ip)
            $getname = GUICtrlRead($name)
            If $getip = "" Then $getip = $ProxyName1[1][1]
            $dosrun = "route add 0.0.0.0 mask 0.0.0.0 " & $getip
            _RunDOS("route delete 0.0.0.0")
            _RunDOS($dosrun)
            RegWrite("HKEY_CURRENT_USER\Software\Policies\Microsoft\Internet Explorer\Restrictions", "NoSelectDownloadDir", "REG_DWORD", "0")
            RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\3", "1803", "REG_DWORD", "0")
            MsgBox(0, "切换下载线路成功", "你现在已经切换到" & $getname)
            Exit
        Case $cancel
            DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $Form1, "int", 500, "long", 0x00090000)
            Exit
    EndSwitch
WEnd
 楼主| 发表于 2008-8-22 00:35:35 | 显示全部楼层
只是要开机改网关。

[ 本帖最后由 lotsunhim 于 2008-8-22 17:19 编辑 ]
发表于 2012-11-14 20:47:44 | 显示全部楼层
来个直观图就好了
发表于 2014-12-23 14:43:08 | 显示全部楼层
学习了,感谢分享!
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-9-28 12:24 , Processed in 0.077943 second(s), 20 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表