vb6.0 怎样获得IP?

来源:百度知道 编辑:UC知道 时间:2024/06/19 17:30:33
怎样让text1显示本机“宽带连接”的IP(不是“本地连接”的IP!)
我想要源码。
谢谢!
winsock怎么做呢?

(利用系统的ipconfig命令重定向到临时文件,vb读取文件处理下就ok了

其他方法一般都要调用系统API了)

画个按钮,画个Timer,画个文本框

timer的Enabled属性设置成false,interval属性设置成1000

然后复制下面代码就可以了

timer纯粹是为了延时,等待临时文件生成的一个很拙劣的办法,如果你用别的方法实现shell同步执行,如用WaitforSingleObject等API函数之类的就不用Timer了,Timer里边的东西都写到按钮事件好了

'按钮点击事件
Private Sub Command1_Click()
Shell "cmd /c ipconfig.exe > " & Environ("temp") & "\ip.txt"
Timer1.Enabled = True
End Sub

'Timer的Timer事件
Private Sub Timer1_Timer()
Dim i As Long, a As String, isFind As Boolean
Open Environ("temp") & "\ip.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, a
If InStr(a, "PPP adapter") > 0 Then
isFind = True
Exit Do
End If
Loop
If isFind Then
For i = 1 To 10
Line Input #1, a
If InStr(a, "IP Address") > 0 Then