Board logo

标题: 关于拨号不重复IP的问题 [打印本页]

作者: sexfio     时间: 2009-4-15 13:07    标题: 关于拨号不重复IP的问题

我想写个拨号不重复IP的代码(用a.txt记录拨过的IP地址,重复就从拨)
搜索了论坛没找到相关的帖子
我用VBS是写出来了,但是放虚拟机用不了
我换了一种写法,虚拟机里可以用了,但是无法完全隐藏dos窗口(我用.exec来捕捉ipconfig返回的字符串)
请教大家了,请大家给个办法,BAT或VBS都可以,谢谢!
作者: HAT     时间: 2009-4-15 14:37
先把你尝试的两个代码贴出来看看?
作者: everest79     时间: 2009-4-15 15:39

ipconfig /all|findstr /i /g:1.txt&&goto :重拔||ipconfig /all|findstr /i "ip address" >1.txt

:重拔
重新拔号
goto :eof

作者: sexfio     时间: 2009-4-15 22:10
谢谢楼上的,不过没实验成功,看来我要好好学习批处理了,都看不懂,5555~~~
作者: sexfio     时间: 2009-4-15 22:18
Public Function GetIP
Set WS = CreateObject("WScript.Shell")
Set aExec = WS.exec("ipconfig")
Set aStdOut = aExec.StdOut
ipconfig = aStdOut.Readall
If InstrRev(ipconfig,"宽带连接",-1,1)=0 then
GetIP=-1
Else
GetIP=InstrRev(ipconfig,":",-1,1)
GetIP=Right(ipconfig,len(ipconfig)-GetIP)
GetIP=trim(GetIP)
GetIP=replace(GetIP,chr(10),"")
GetIP=replace(GetIP,chr(13),"")
End If
set WS = nothing
End Function

这个是我自己写的判断IP的调用(没连接返回-1),就是从ipconfig里找Ip,但是.exec没法完全隐藏dos窗口,我不想写txt再删除,不知道有其他好的办法没

这个是网上找的,但是不知道为什么虚拟机里用不了
Public Function GetIP
ComputerName="."
Dim objWMIService,colItems,objItem,objAddress
GetIP_i=0
Set objWMIService = GetObject("winmgmts:\\" & ComputerName & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")
For Each objItem in colItems
GetIP_i=GetIP_i+1
For Each objAddress in objItem.IPAddress
If objAddress <> "" then
GetIP = objAddress
End If
Next
Next
If GetIP_i=1 then
GetIP=-1
End If
End Function

没连接返回-1是我自己加上去的,我看不大懂,虚拟机里卡在Set objWMIService = GetObject("winmgmts:\\" & ComputerName & "\root\cimv2")这句上了,不知道为什么

有了调用,其他就简单了,就不发了,大家帮我看看哈:D

[ Last edited by sexfio on 2009-4-15 at 22:19 ]
作者: everest79     时间: 2009-4-16 00:53

ipconfig /all|findstr /i /g:1.txt&&goto pppoe||ipconfig /all|findstr /i "ip address" >1.txt
goto :eof

:ppooe
rasdial /disconnect
rasdial xDSL username password
goto :eof
xdsl是你电脑上的宽带名称