cvwyg 发表于 2011-9-25 19:45:51

ip等地址修改贵工具 求高手精简源代码

本帖最后由 cvwyg 于 2011-9-26 12:33 编辑

俺是个新新手~~搞个ip地址修改的~很简单~基本参考网上·~但是个gui,太复杂~~
#Region ;**** 参数创建于 ACNWrapper_GUI ****
#AutoIt3Wrapper_Outfile=IP地址修改器.exe
#EndRegion ;**** 参数创建于 ACNWrapper_GUI ****

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Opt("GUICloseOnESC", 0);在按下 ESC 时不退出
Opt("TrayAutoPause", 0) ;右下角图标点击不暂停
Opt("TrayMenuMode", 1) ;这里是设置任务栏图标的菜单,AU3默认的是点击后暂停脚本,使用这个后将取消默认值,值保留现在脚本里面的菜单和操作


#Region ### START Koda GUI section ### Form=c:\documents and settings\administrator\桌面\au3\form1.kxf
$Form1_1 = GUICreate("IP地址修改器.exe", 624, 255, 192, 124)
$Label1 = GUICtrlCreateLabel("IP地址:", 16, 32, 39, 20)
GUICtrlSetFont(-1, 8.5, 400, 0, "微软雅黑")
$Label2 = GUICtrlCreateLabel("子网掩码:", 296, 32, 51, 20)
GUICtrlSetFont(-1, 8.5, 400, 0, "微软雅黑")
$Label3 = GUICtrlCreateLabel("DNS:", 16, 80, 30, 20)
GUICtrlSetFont(-1, 8.5, 400, 0, "微软雅黑")
$Label4 = GUICtrlCreateLabel("网关:", 296, 80, 29, 20)
GUICtrlSetFont(-1, 8.5, 400, 0, "微软雅黑")
$Label5 = GUICtrlCreateLabel("累加计算机名称和IP地址最后一位", 8, 168, 172, 20)
GUICtrlSetFont(-1, 8.5, 400, 0, "微软雅黑")
$Button1 = GUICtrlCreateButton("累加+1", 216, 152, 65, 33)
GUICtrlSetFont(-1, 8.5, 400, 0, "微软雅黑")
$Button2 = GUICtrlCreateButton("执行", 512, 208, 65, 33)
GUICtrlSetFont(-1, 8.5, 400, 0, "微软雅黑")
$Input1 = GUICtrlCreateInput("192", 72, 24, 41, 24)
GUICtrlSetFont(-1, 8.5, 400, 0, "微软雅黑")
$Input2 = GUICtrlCreateInput("168", 128, 24, 41, 24)
GUICtrlSetFont(-1, 8.5, 400, 0, "微软雅黑")
$Input3 = GUICtrlCreateInput("1", 184, 24, 41, 24)
GUICtrlSetFont(-1, 8.5, 400, 0, "微软雅黑")
$Input4 = GUICtrlCreateInput("2", 240, 24, 41, 24)
GUICtrlSetFont(-1, 8.5, 400, 0, "微软雅黑")
$Input5 = GUICtrlCreateInput("255", 352, 32, 41, 24)
GUICtrlSetFont(-1, 8.5, 400, 0, "微软雅黑")
$Input6 = GUICtrlCreateInput("255", 408, 32, 41, 24)
GUICtrlSetFont(-1, 8.5, 400, 0, "微软雅黑")
$Input7 = GUICtrlCreateInput("255", 464, 32, 41, 24)
GUICtrlSetFont(-1, 8.5, 400, 0, "微软雅黑")
$Input8 = GUICtrlCreateInput("0", 528, 32, 41, 24)
GUICtrlSetFont(-1, 8.5, 400, 0, "微软雅黑")
$Input9 = GUICtrlCreateInput("192", 72, 72, 41, 24)
GUICtrlSetFont(-1, 8.5, 400, 0, "微软雅黑")
$Input10 = GUICtrlCreateInput("168", 128, 72, 41, 24)
GUICtrlSetFont(-1, 8.5, 400, 0, "微软雅黑")
$Input11 = GUICtrlCreateInput("1", 184, 72, 41, 24)
GUICtrlSetFont(-1, 8.5, 400, 0, "微软雅黑")
$Input12 = GUICtrlCreateInput("1", 240, 72, 41, 24)
GUICtrlSetFont(-1, 8.5, 400, 0, "微软雅黑")
$Input13 = GUICtrlCreateInput("192", 352, 72, 41, 24)
GUICtrlSetFont(-1, 8.5, 400, 0, "微软雅黑")
$Input14 = GUICtrlCreateInput("168", 408, 72, 41, 24)
GUICtrlSetFont(-1, 8.5, 400, 0, "微软雅黑")
$Input15 = GUICtrlCreateInput("1", 464, 72, 41, 24)
GUICtrlSetFont(-1, 8.5, 400, 0, "微软雅黑")
$Input16 = GUICtrlCreateInput("2", 528, 72, 41, 24)
GUICtrlSetFont(-1, 8.5, 400, 0, "微软雅黑")
$Label6 = GUICtrlCreateLabel(" 计算机名称:", 16, 120, 73, 20)
GUICtrlSetFont(-1, 8.5, 400, 0, "微软雅黑")
$student = GUICtrlCreateInput("student", 104, 112, 65, 24)
GUICtrlSetFont(-1, 8.5, 400, 0, "微软雅黑")
$Input18 = GUICtrlCreateInput("2", 184, 112, 65, 24)
GUICtrlSetFont(-1, 8.5, 400, 0, "微软雅黑")
$Button3 = GUICtrlCreateButton("一致", 320, 152, 65, 33)
GUICtrlSetFont(-1, 8.5, 400, 0, "微软雅黑")
$Button4 = GUICtrlCreateButton("默认一", 416, 152, 65, 33) ;默认一为本机电脑IP地址
GUICtrlSetFont(-1, 8.5, 400, 0, "微软雅黑")
$Button5 = GUICtrlCreateButton("默认二", 512, 152, 65, 33) ;默认二为一般局域网电脑IP地址
GUICtrlSetFont(-1, 8.5, 400, 0, "微软雅黑")
$Label7 = GUICtrlCreateLabel("DNS2默认为202.197.64.6    计算机名称为student_XX", 8, 200, 300, 20)
GUICtrlSetFont(-1, 8.5, 400, 0, "微软雅黑")

$MenuItem1 = TrayCreateItem("关于")
TrayCreateItem("")
$MenuItem2 = TrayCreateItem("退出工具")

TraySetState()
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


Dim $name, $name1, $name2, $xxx, $student01
$name = IniRead("ip_name.ini", "NAME", "name", "") ;开始时读取配置文件ip_name.ini
$name1 = IniRead("ip_name.ini", "NAME", "name1", "")
$name2 = IniRead("ip_name.ini", "NAME", "name2", "")

$ip = IniRead("ip_name.ini", "IP", "ip", "")
$ip1 = IniRead("ip_name.ini", "IP", "ip1", "")
$ip2 = IniRead("ip_name.ini", "IP", "ip2", "")
$ip3 = IniRead("ip_name.ini", "IP", "ip3", "")
$ip4 = IniRead("ip_name.ini", "IP", "ip4", "")

$mask = IniRead("ip_name.ini", "MASK", "mask", "")
$mask1 = IniRead("ip_name.ini", "MASK", "mask1", "")
$mask2 = IniRead("ip_name.ini", "MASK", "mask2", "")
$mask3 = IniRead("ip_name.ini", "MASK", "mask3", "")
$mask4 = IniRead("ip_name.ini", "MASK", "mask4", "")

$dns = IniRead("ip_name.ini", "DNS", "dns", "")
$dns1 = IniRead("ip_name.ini", "DNS", "dns1", "")
$dns2 = IniRead("ip_name.ini", "DNS", "dns2", "")
$dns3 = IniRead("ip_name.ini", "DNS", "dns3", "")
$dns4 = IniRead("ip_name.ini", "DNS", "dns4", "")

$gate = IniRead("ip_name.ini", "GATE", "gate", "")
$gate1 = IniRead("ip_name.ini", "GATE", "gate1", "")
$gate2 = IniRead("ip_name.ini", "GATE", "gate2", "")
$gate3 = IniRead("ip_name.ini", "GATE", "gate3", "")
$gate4 = IniRead("ip_name.ini", "GATE", "gate4", "")


GUICtrlSetData($Input1, $ip1) ;读取后写入到input里面
GUICtrlSetData($Input2, $ip2)
GUICtrlSetData($Input3, $ip3)
GUICtrlSetData($Input4, $ip4)

GUICtrlSetData($Input5, $dns1)
GUICtrlSetData($Input6, $dns2)
GUICtrlSetData($Input7, $dns3)
GUICtrlSetData($Input8, $dns4)

GUICtrlSetData($Input9, $mask1)
GUICtrlSetData($Input10, $mask2)
GUICtrlSetData($Input11, $mask3)
GUICtrlSetData($Input12, $mask4)

GUICtrlSetData($Input13, $gate1)
GUICtrlSetData($Input14, $gate2)
GUICtrlSetData($Input15, $gate3)
GUICtrlSetData($Input16, $gate4)

GUICtrlSetData($student, $name1)
GUICtrlSetData($Input18, $name2)


TraySetClick(8) ;按下鼠标次要按键(通常右键)

$dns002 = "202.197.64.6" ;其他dns(以后再加吧)

While 1
        _ReduceMemory(@AutoItPID) ;内存整理

        $msg = TrayGetMsg() ;右击图标菜单事件
        If $msg = $MenuItem2 Then
                Exit
        EndIf
        If $msg = $MenuItem1 Then
                MsgBox("", "关于", "就这样吧~~!!!")
        EndIf

        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1 ;累加按钮
                        leijia()
                Case $Button2 ;执行按钮
                        ip_xiugai_func()
                        name_xiugai_func()
                        $tishi = MsgBox(1 + 32, "IP地址修改", "OK!已经搞好了,现在需要重启您的电脑~!" & @CRLF & "" & @CRLF & "" & @CRLF & "6秒钟后将自动关闭并重启~", 6)
                        Select
                                Case $tishi = 1 Or $tishi = -1
                                        Shutdown(2)
                                Case $tishi = 2
                                        WinClose("IP地址修改")
                        EndSelect
                Case $Button3 ;一致按钮
                        $ip04 = GUICtrlRead($Input4)
                        GUICtrlSetData($Input18, $ip04)
                        name_fun()
                        ip_func()
                Case $Button4 ; 默认一按钮
                        moren_1_func()
                Case $Button5 ; 默认二按钮
                        moren_2_func()
        EndSwitch
WEnd

Func leijia() ;累加
        $Input04 = GUICtrlRead($Input4)
        $Input018 = GUICtrlRead($Input18)
        If $Input04 < 254 Then ;判断ip地址是否大于254
                $Input04 = $Input04 + 1 ;叠加+1
                $Input018 = $Input018 + 1
                GUICtrlSetData($Input4, $Input04)
                GUICtrlSetData($Input18, $Input018)
        ElseIf $Input04 >= 254 Then ;提示错误并恢复默认
                MsgBox(64, "提示", "IP地址不能大于或等于255或者小于等于1" & @CRLF & "现在将恢复ip最后一位默认为2")
                GUICtrlSetData($Input4, "2")
                GUICtrlSetData($Input18, "2")
        EndIf
        name_fun() ;并且执行写入ini函数
        ip_func()
EndFunc   ;==>leijia

Func name_fun() ;写入ini的name
        Dim $name, $name01, $name02, $student01
        $student01 = GUICtrlRead($student)
        $name02 = GUICtrlRead($Input18)
        $name = $student01 & "_" & $name02
        IniWrite("ip_name.ini", "NAME", "name1", $student01)
        IniWrite("ip_name.ini", "NAME", "name2", $name02)
        IniWrite("ip_name.ini", "NAME", "name", $name)

EndFunc   ;==>name_fun

Func ip_func() ;写入ini的ip
        Dim $Input01, $Input02, $Input03, $Input04
        $Input01 = GUICtrlRead($Input1)
        $Input02 = GUICtrlRead($Input2)
        $Input03 = GUICtrlRead($Input3)
        $Input04 = GUICtrlRead($Input4)
        $ip = $Input01 & "." & $Input02 & "." & $Input03 & "." & $Input04
        IniWrite("ip_name.ini", "IP", "ip1", $Input01)
        IniWrite("ip_name.ini", "IP", "ip2", $Input02)
        IniWrite("ip_name.ini", "IP", "ip3", $Input03)
        IniWrite("ip_name.ini", "IP", "ip4", $Input04)
        IniWrite("ip_name.ini", "IP", "ip", $ip)
EndFunc   ;==>ip_func

Func dns_func() ;写入ini的dns
        Dim $Input05, $Input06, $Input07, $Input08
        $Input05 = GUICtrlRead($Input5)
        $Input06 = GUICtrlRead($Input6)
        $Input07 = GUICtrlRead($Input7)
        $Input08 = GUICtrlRead($Input8)
        $dns = $Input05 & "." & $Input06 & "." & $Input07 & "." & $Input08
        IniWrite("ip_name.ini", "DNS", "dns1", $Input05)
        IniWrite("ip_name.ini", "DNS", "dns2", $Input06)
        IniWrite("ip_name.ini", "DNS", "dns3", $Input07)
        IniWrite("ip_name.ini", "DNS", "dns4", $Input08)
        IniWrite("ip_name.ini", "DNS", "dns", $dns)
        MsgBox("", "dns", $dns)
EndFunc   ;==>dns_func

Func mask_func() ;写入ini的mask(子网掩码)
        Dim $Input09, $Input010, $Input011, $Input012
        $Input09 = GUICtrlRead($Input9)
        $Input010 = GUICtrlRead($Input10)
        $Input011 = GUICtrlRead($Input11)
        $Input012 = GUICtrlRead($Input12)
        $mask = $Input09 & "." & $Input010 & "." & $Input011 & "." & $Input012
        IniWrite("ip_name.ini", "MASK", "mask1", $Input09)
        IniWrite("ip_name.ini", "MASK", "mask2", $Input010)
        IniWrite("ip_name.ini", "MASK", "mask3", $Input011)
        IniWrite("ip_name.ini", "MASK", "mask4", $Input012)
        IniWrite("ip_name.ini", "MASK", "mask", $mask)
        MsgBox("", "mask", $mask)
EndFunc   ;==>mask_func

Func gate_func() ;写入ini的gate(网关)
        Dim $Input013, $Input014, $Input015, $Input016
        $Input013 = GUICtrlRead($Input13)
        $Input014 = GUICtrlRead($Input14)
        $Input015 = GUICtrlRead($Input15)
        $Input016 = GUICtrlRead($Input16)
        $gate = $Input013 & "." & $Input014 & "." & $Input015 & "." & $Input016
        IniWrite("ip_name.ini", "GATE", "gate1", $Input013)
        IniWrite("ip_name.ini", "GATE", "gate2", $Input014)
        IniWrite("ip_name.ini", "GATE", "gate3", $Input015)
        IniWrite("ip_name.ini", "GATE", "gate4", $Input016)
        IniWrite("ip_name.ini", "GATE", "gate", $gate)
        MsgBox("", "gate", $gate)
EndFunc   ;==>gate_func

Func ip_xiugai_func() ;修改IP地址函数
        RunWait('netsh interface ip set address name = "本地连接" source = static addr = ' & $ip & ' mask = ' & $mask & ' gateway = ' & $gate & ' gwmetric = 0', "c:\windows\system32", @SW_HIDE)
        RunWait('netsh interface ip set dns name = "本地连接" source = static addr = ' & $dns & ' register = PRIMARY', @SystemDir, @SW_HIDE)
        RunWait('netsh interface ip add dns name = "本地连接" addr = ' & $dns002 & ' index=2', @SystemDir, @SW_HIDE)
EndFunc   ;==>ip_xiugai_func

Func name_xiugai_func() ;修改name函数
        RegWrite("HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName", "ComputerName", "REG_SZ", $name)
        RegWrite("HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters", "NV Hostname", "REG_SZ", $name)
        RegWrite("HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters", "Hostname", "REG_SZ", $name)
EndFunc   ;==>name_xiugai_func

Func moren_1_func() ;默认一函数
        GUICtrlSetData($Input1, "218")
        GUICtrlSetData($Input2, "196")
        GUICtrlSetData($Input3, "119")
        GUICtrlSetData($Input4, "246")

        GUICtrlSetData($Input5, "202")
        GUICtrlSetData($Input6, "197")
        GUICtrlSetData($Input7, "64")
        GUICtrlSetData($Input8, "6")

        GUICtrlSetData($Input9, "255")
        GUICtrlSetData($Input10, "255")
        GUICtrlSetData($Input11, "255")
        GUICtrlSetData($Input12, "0")

        GUICtrlSetData($Input13, "218")
        GUICtrlSetData($Input14, "196")
        GUICtrlSetData($Input15, "119")
        GUICtrlSetData($Input16, "254")

        GUICtrlSetData($student, "way")
        GUICtrlSetData($Input18, "pig")

        name_fun() ;并执行写入ini
        ip_func()
        mask_func()
        gate_func()
        dns_func()

EndFunc   ;==>moren_1_func

Func moren_2_func() ;默认二函数
        GUICtrlSetData($Input1, "192")
        GUICtrlSetData($Input2, "168")
        GUICtrlSetData($Input3, "1")
        GUICtrlSetData($Input4, "2")

        GUICtrlSetData($Input5, "192")
        GUICtrlSetData($Input6, "168")
        GUICtrlSetData($Input7, "1")
        GUICtrlSetData($Input8, "1")

        GUICtrlSetData($Input9, "255")
        GUICtrlSetData($Input10, "255")
        GUICtrlSetData($Input11, "255")
        GUICtrlSetData($Input12, "0")

        GUICtrlSetData($Input13, "192")
        GUICtrlSetData($Input14, "168")
        GUICtrlSetData($Input15, "1")
        GUICtrlSetData($Input16, "1")

        GUICtrlSetData($student, "student")
        GUICtrlSetData($Input18, "2")

        name_fun() ;并执行写入ini
        ip_func()
        mask_func()
        gate_func()
        dns_func()

EndFunc   ;==>moren_2_func

Func _ReduceMemory($i_PID = -1);整理内存
        If $i_PID <> -1 Then
                Local $ai_Handle = DllCall("kernel32.dll", 'int', 'OpenProcess', 'int', 0x1f0fff, 'int', False, 'int', $i_PID)
                Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', $ai_Handle)
                DllCall('kernel32.dll', 'int', 'CloseHandle', 'int', $ai_Handle)
        Else
                Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', -1)
        EndIf

        Return $ai_Return
EndFunc   ;==>_ReduceMemory

wei999 发表于 2011-9-25 20:27:09

是够多的啊,。。。。

xms77 发表于 2011-9-25 21:06:08

回复 1# cvwyg
请问楼主,内存整理的目的是什么?

cvwyg 发表于 2011-9-25 22:33:33

回复 3# xms77


    那个是单门整理au3程序的内存的~效果很明显~~
不加内存6m多,加后就600k左右~~~
原来抄袭网上的~~后来一直用~~~

hzxymkb 发表于 2011-9-25 23:02:43

请看本版置顶的帖子!
页: [1]
查看完整版本: ip等地址修改贵工具 求高手精简源代码