本帖最后由 batman 于 2013-9-5 19:53 编辑
变量自己改,如果问题解决了,请将钱捐到论坛基金,具体事项找Batcher。。。- '初始化全局变量
- Dim AdslName, AdslUser, AdslPassword, Url, Ip, File, Text, OK, Times, StartTime
- AdslName = "xxxx"
- AdslUser = "xxxx"
- AdslPassword = "xxxxxx"
- Url = "http://iframe.ip138.com/ic.asp"
- Ip = "www.baidu.com"
- File = "ip.txt"
- OK = vbNullString
-
- '输入断网时间
- Do Until Times <> 0
- Times = Int(InputBox("请输入自动断网的时间,单位为分钟,默认为60分钟",,60))
- Loop
- StartTime = Now
-
- '判断ip.txt最后一次访问时间到现在是不是过了24小时
- GetText File, "test", Null
-
- '拔号循环
- Adsl "disconnect"
- WScript.Sleep 1000
- For i = 1 To 5
- Adsl "connect"
- WScript.Sleep 1000
- Juge
- If Juge = 0 Then
- GetIp : Text = vbNullString
- GetText File, "read", Null
- If InStr(Text, GetIp) = 0 Then
- GetText File, "write", GetIp
- OK = "ok"
- Exit For
- Else
- Adsl "disconnect"
- End If
- End If
- Next
- If OK <> "ok" Then
- MsgBox "拔号出错"
- WScript.Quit
- End if
-
- '在没到达断网时间内每10秒检测一次网络发现断线后重拔
- Do
- If DateDiff("s", StartTime, Now) >= Times * 60 Then
- Adsl "disconect"
- WScript.Quit
- End If
- Juge
- If Juge = 1 Then
- Adsl "connect"
- End If
- WScript.Sleep 10 * 1000
- Loop
-
- Function Juge
- '判断网络通畅
- Juge = 1
- Dim objWMI, objItems, objItem
- Set objWMI = GetObject("Winmgmts:")
- Set objItems = objWMI.ExecQuery _
- ("Select * From Win32_PingStatus " _
- & "Where Address = '" & Ip & "'")
- For Each objItem In objItems
- If objItem.ResponseTime > 0 Then Juge = 0
- Next
- Set objItems = Nothing
- Set objWMI = Nothing
- End Function
-
- Function Adsl(Types)
- 'ADSL拔号版块
- Dim objSHELL
- Set objSHELL = CreateObject("Wscript.Shell")
- If Types = "connect" Then
- objSHELL.Run "rasdial.exe " & AdslName _
- & " " & AdslUser & " " & Adslpassword, 0, 0
- Else
- objSHELL.Run "rasdial.exe /disconnect", 0, 0
- End If
- Set objSHELL = Nothing
- End Function
-
- Function GetIp
- '获取外网IP
- Dim objDOM, Arr, Arr2
- Set objDOM = WScript.GetObject(Url)
- Do Until objDOM.Readystate = "complete"
- WScript.Sleep 200
- Loop
- Arr = Split(objDOM.DocumentElement.Innertext, "[")
- Arr2 = Split(Arr(1), "]")
- GetIp = Arr2(0)
- Set objDOM = Nothing
- End Function
-
- Function GetText(File, Types, GetIp)
- '文本读、写版块
- Dim objFSO
- Set objFSO = CreateObject("Scripting.FileSystemObject")
- If Not objFSO.FileExists(File) Then _
- objFSO.OpenTextFile(File, 2, True).WriteLine "IP列表"
- If Types = "read" Then
- Text = objFSO.OpenTextFile(File).ReadAll
- Else
- If Types = "write" Then
- objFSO.OpenTextFile(File, 8).WriteLine GetIp
- Else
- oldday = objFSO.GetFile(File).DateLastModified
- If DateDiff("h", oldday, Now) > 24 Then _
- objFSO.OpenTextFile(File, 2, True).WriteLine "IP列表"
- End If
- End If
- Set objFSO = Nothing
- End Function
复制代码
|