基于AutoIt3的运维工具

#Region ;**** 编译指令由 AutoIt3Wrapper 选项编译窗口创建 ****
#AutoIt3Wrapper_Icon=favicon.ico
#AutoIt3Wrapper_Compile_Both=y
#EndRegion ;**** 编译指令由 AutoIt3Wrapper 选项编译窗口创建 ****
; #AutoIt3Wrapper_UseX64=n
#include <Constants.au3> ; for Ping
#include <GUIConstantsEx.au3> ; for GUI
#include <IE.au3> ; for 浏览器
#include <Date.au3> ; for data


; ************** 修改版本号时,请同时修改对应网址的版本 **************
; 在 EipFunc.au3 中修改版本号
#include <SsoFunc.au3> ; 我的自定义函数

Global $logfile = 'EipRepairLog-' & @MON & '-' & @MDAY &'.txt'
FileWriteLine($logfile, @CRLF & @YEAR & '-' & @MON & '-' & @MDAY & ' ' & @HOUR & ":" & @MIN & ":" & @SEC) ;---------日志


; 检测操作系统位数
$myOsArch = ' [' & OsArch() & '位]'
; 用户界面初始化  --  版本自动更新
$headlabel = "通讯测试SSO-" & versionGet()
FileWriteLine($logfile, $headlabel) ;---------日志
GUICreate($headlabel, 400, 280)
; GUISetBkColor(0xffffff)
GUISetBkColor(0x8ef5b2)

$hostsbutton = GUICtrlCreateButton("打开hosts文件", 30, 200, 100, 30)
$eipbutton = GUICtrlCreateButton("打开SSO网址", 160, 200, 100, 30)
; $okbutton = GUICtrlCreateButton("确定", 290, 200, 70, 30)


; 检测是否内网
$isInNetStr = isInNetOrNot()
; 输出您的IP
$iplabel = "您好," & @UserName & "! 您的IP是:" & @IPAddress1 & " " & $isInNetStr & $myOsArch
FileWriteLine($logfile, $iplabel) ;---------日志
GUICtrlCreateLabel($iplabel, 30, 250)
GUISetState(@SW_SHOW)



; 判断是否云
$isYun = 1 ; 0--CloudDesk | 1--NotCloud
$isYunStr = isCloudOrNot()
Global $testIP
If $isYun == 1 Then
    $testIP = 'xxx.xxx.xxx.xxx'
Else
    $testIP = 'xxx.xxx.xxx.xxx'
EndIf

; ping IP 并返回
$piplabel = "测试是否能连接至 " & $testIP
FileWriteLine($logfile, $piplabel) ;---------日志
GUICtrlCreateLabel($piplabel, 30, 20)
Sleep(100)
$mypiplabel = myping($testIP)
FileWriteLine($logfile, $mypiplabel) ;---------日志
GUICtrlCreateLabel($mypiplabel, 30, 40)
Sleep(100)


; 检测eip.***.com是否xxx.xxx.xxx.xxx
$tiplabel = "开始检测eip.***.com 是否 " & $testIP
FileWriteLine($logfile, $tiplabel) ;---------日志
GUICtrlCreateLabel($tiplabel, 30, 70)
Sleep(100)
$netEqualIp = tcpEqualIp("eip.***.com", $testIP); 返回 1 表示正常
Global $myHostFile = @SystemDir & "driversetchosts"
If $netEqualIp == 1 Then
    $tcplabel = "eip.***.com 的IP地址 [ 是 ] " & $testIP
    FileWriteLine($logfile, $tcplabel) ;---------日志
    GUICtrlCreateLabel($tcplabel, 30, 90)
Else
    $tcplabel = "[ 不是 ] " & $testIP & " ,而是 " & $netEqualIp
    FileWriteLine($logfile, $tcplabel) ;---------日志
    GUICtrlCreateLabel($tcplabel, 30, 90)
    ; 写hosts文件
    GUICtrlCreateLabel("开始写入hosts文件", 30, 120)
    FileWriteLine($logfile, "开始写入hosts文件-" & $myHostFile) ;---------日志
    ; 对于64位电脑是System32文件夹路径, 对于32位是SystemWoW64路径
    ; GUICtrlCreateLabel($myHostFile, 30, 250) ; test for url
    ; 判断hosts文件是否存在
    If FileExists($myHostFile) Then
        FileWriteLine($logfile, "hosts文件已存在") ;---------日志
        GUICtrlCreateLabel("hosts文件已存在", 30, 140)
        $inhosts = strInHosts($myHostFile, $testIP, 'eip.***.com')
        ; 海外要添加sso.***.com 至hosts文件中
        $inhosts1 = strInHosts($myHostFile, 'xxx.xxx.xxx.xxx', 'sso.***.com')
        FileWriteLine($logfile, $inhosts & '  eip') ;---------日志
        FileWriteLine($logfile, $inhosts1 & '  sso') ;---------日志
        GUICtrlCreateLabel($inhosts, 30, 160)
    Else
        FileWriteLine($logfile, "hosts文件不存在,开始新建并写入hosts文件") ;---------日志
        GUICtrlCreateLabel("hosts文件不存在,开始新建并写入hosts文件", 30, 140)
        writeHosts($myHostFile)
        FileWriteLine($logfile, "写入hosts文件完成") ;---------日志
        GUICtrlCreateLabel("写入hosts文件完成", 30, 160)
    EndIf
EndIf
Sleep(100)




; writeHosts('hosts') ; 测试写入hosts文件



While 1
  $msg = GUIGetMsg()

  Select
    Case $msg = $eipbutton
        $oIE = _IECreate("http://sso.***.com", 0, 1, 0); 打开网页
        FileWriteLine($logfile, "打开EIP-" & $oIE) ;---------日志
        ; ExitLoop
    Case $msg = $hostsbutton
        $openhosts = Run(@WindowsDir & "Notepad.exe " & ' ' & @SystemDir & "driversetchosts")
        FileWriteLine($logfile, "打开hosts文件-" & $openhosts) ;---------日志
    Case $msg = $GUI_EVENT_CLOSE
        ; 关闭对话框事件
        FileWriteLine($logfile, "关闭退出" & @CRLF) ;---------日志
        FileClose($logfile)
        ExitLoop
  EndSelect
WEnd
原文地址:https://www.cnblogs.com/mjy2wxy/p/11468550.html