看这个能用不,上万行就有点慢了- Option Explicit
- Dim strBegin_ip,strEnd_ip,FSO
-
- strBegin_ip=InputBox("请输入起始IP地址:")
- If Not IsIP(strBegin_ip) Then
- MsgBox "非法IP!",0,"错误"
- WScript.Quit
- End If
- strEnd_ip=InputBox("请输入结束IP地址")
- If Not IsIP(strEnd_ip) Then
- MsgBox "非法IP!",0,"错误"
- WScript.Quit
- End If
- Set FSO=CreateObject("scripting.filesystemobject")
- FSO.CreateTextFile("IP地址.txt",True).Write(GenerateIP(strBegin_ip,strEnd_ip))
- CreateObject("wscript.shell").run "IP地址.txt"
-
- Function GenerateIP(strBegin,strEnd)
- Dim arrBegin,arrEnd,intSum_begin,intSum_end
- Dim intSeg1,intMod1,intSeg2,intMod2,intSeg3,intMod3,intSeg4
- Dim i
- arrBegin=Split(strBegin,".",-1)
- arrEnd=Split(strEnd,".",-1)
- intSum_begin=arrBegin(0)*256^3+arrBegin(1)*256^2+arrBegin(2)*256+arrBegin(3)
- intSum_end=arrEnd(0)*256^3+arrEnd(1)*256^2+arrEnd(2)*256+arrEnd(3)
- If intSum_end-intSum_begin<0 Then
- MsgBox "结束IP大于起始IP",0,"错误"
- WScript.Quit
- End If
- For i = intSum_begin To intSum_end
- intSeg1=int(i/256^3):intMod1=i-intSeg1*256^3
- intSeg2=Int(intMod1/256^2):intMod2=intMod1-intSeg2*256^2
- intSeg3=Int(intMod2/256):intMod3=intMod2-intSeg3*256
- intSeg4=intMod3
- GenerateIP=GenerateIP&intSeg1&"."&intSeg2&"."&intSeg3&"."&intSeg4&vbCrLf
- Next
- End Function
-
- Function IsIP(strIPAddress)
- Dim oRegex
- Set oRegex=CreateObject("VBscript.Regexp")
- oRegex.Global=True
- oRegex.Pattern="((?:(?:25[0-5]|2[0-4]\d|((1\d{2})|([1-9]?\d)))\.){3}(?:25[0-5]|2[0-4]\d|((1\d{2})|([1-9]?\d))))"
- IsIP=oRegex.Test(strIPAddress)
- End Function
复制代码
|