'Set to False to throw an error when it can't connect, True to ignore connection errors 'best set to True when running from the task scheduler; False when running manually Const NoError = False 'Set to False to use a messagebox or True to log to files Const LogToFile = False 'Full Paths To the two logfiles: Const LogFileIP = "c:\CurrentIP.txt" Const LogFileName = "c:\CurrentHostName.txt" '======================================================= ' DO NOT ALTER BELOW THIS LINE! '======================================================= Const ForReading = 1, ForWriting = 2, ForAppending = 8 Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0 Const URL = "http://140.119.210.208/cgi-bin/xxyxx" Dim Raw, IPText, NameText, WasError, x If LogToFIle = True then if LogFileIP = "" or LogFileName = "" then Wscript.Echo "LogFileIP or LogFIleName is not set!" & vbCRLF & " Exiting!" Wscript.Quit end if end if GetRawData if LogToFIle = True then WriteToFile else ' Wscript.Echo "你目前使用的IP是: " & IPText strIP = "你目前使用的IP是: " & IPText end If Select Case Left(IPText,7) Case "140.119" ' Wscript.Echo "你目前使用的IP是: " & IPText & "(你的IP在政大校園網路內)" strJg = "(你的IP在政大校園網路內)" Case Else ' Wscript.Echo "你目前使用的IP是: " & IPText & "(你的IP不在政大校園網路內)" strJg = "(你的IP不在政大校園網路內)" Wscript.Quit End Select strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colOSes = objWMIService.ExecQuery("Select * from Win32_OperatingSystem") For Each objOS in colOSes ' Wscript.Echo "Computer Name: " & objOS.CSName ' Wscript.Echo "Caption: " & objOS.Caption 'Name strOsname = objOS.Caption ' Wscript.Echo "Version: " & objOS.Version 'Version & build ' Wscript.Echo "Build Number: " & objOS.BuildNumber 'Build ' Wscript.Echo "Build Type: " & objOS.BuildType ' Wscript.Echo "OS Type: " & objOS.OSType ' Wscript.Echo "Other Type Description: " & objOS.OtherTypeDescription Next Dim Col, Obj, strComputer, Wmi strComputer = "." Set Wmi = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set Col = Wmi.ExecQuery("SELECT * FROM Win32_Processor",,48) For Each Obj in Col '-> X86 If InStr(LCase(Obj.Caption),LCase("x86")) Then 'Wscript.Echo "目前執行的是32位元作業系統 OS Caption: " & Obj.Caption strOsx = "32位元" & vbCRLF & "OS Caption: " & Obj.Caption End If '-> X64 If InStr(LCase(Obj.Caption),LCase("x64")) Then 'Wscript.Echo "目前執行的是64位元作業系統 OS Caption: " & Obj.Caption strOsx = "64位元" & vbCRLF & "OS Caption: " & Obj.Caption End If Wscript.Echo strIP & strJg & vbCRLF & strOsname & strOsx Next Sub GetRawData Err.Clear Set WshShell = WScript.CreateObject("WScript.Shell") If NoError = True then On Error Resume Next end if Set Http = CreateObject("Microsoft.XmlHttp") Http.open "GET", URL, FALSE Http.send "" IPText = http.responseText If NoError = True then On Error GoTo 0 end if if Err.Number <> 0 then if NoError = False then MsgBox "Could not connect to server " & URL & vbCRLF & " exiting" Wscript.Quit else WasError = True end if end if Err.Clear Set Http = Nothing Set WshShell = Nothing End Sub Sub WriteToFile if LogFileIP <> "" and LogFileName <> "" and IPText <> "" then Set fs = CreateObject("Scripting.FileSystemObject") Set f = fs.OpenTextFile(LogFileIP, ForWriting, True, TristateFalse) f.WriteLine (IPText) f.close Set f = Nothing Set fs = Nothing end if End Sub