以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- 代码提示出错 (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=71350) |
-- 作者:qingwuzu -- 发布时间:2015/7/9 19:16:00 -- 代码提示出错 Dim i As Integer Dim HostName As String=System.Net.Dns.GetHostName \'获得本机的机器名 Dim IPAdress As System.Net.IPAddress=System.Net.Dns.GetHostByName(HostName).AddressList.GetValue(0) \'获得本机的IP地址 Dim ip99 As String=IPAdress.Tostring If ip99.contains(mid(IP1,1,5))=0 Then \'如果不是通过公司局域网的IP1地址上网(即通过外网上网,或通过公司局域网内的路由器上网) \'由于不知道飞的代码如何转化为字符串,所以参考lin_hailun的代码,均在http://www.foxtable.com/bbs/dispbbs.asp?BoardID=2&ID=24372&skin=0 \'但lin_hailun采用的http://city.ip138.com/city.asp提供的城市是错误的,至少我单位的解释是错误的,所以采用飞的http://ip.qq.com/,如果不需要获取城市代码,采用lin_hailun的代码更加简洁. Dim web As New System.Windows.Forms.WebBrowser() web.Navigate("http://ip.qq.com/") Do Until web.ReadyState = 4 Application.DoEvents Loop Dim elems As System.Windows.Forms.HtmlElementCollection Elems = web.Document.GetElementsByTagName("Body") \'根据标签得到数据集合 Dim data As String = elems(0).InnerText Dim start As Integer = data.IndexOf("IP为") + 4 Dim ip91 As String =trim(data.SubString(start,15)) \'IP地址,最多15个字符 Dim i As Integer Dim j As String For i =8 To 15 \'IP地址至少7位 j =mid(ip91,i,1) If j=chr(10) Then ip91=mid(ip91,1,i-1) \'最终的IP地址 Exit For End If Next start = data.IndexOf("IP所在地为") + 9 Dim ip92 As String=trim(data.SubString(start,15)) \'IP地址对应的城市,最多15个字符 For i =6 To 15 \'城市最少5个字符 j =mid(ip92,i,1) If j=" " Then ip92=mid(ip92,1,i-1) \'最终的城市,忽略后面的运营商 Exit For End If Next ip91=ip91 & "|" & ip92 \'合并
|
-- 作者:大红袍 -- 发布时间:2015/7/9 19:22:00 -- Dim web As New System.Windows.Forms.WebBrowser() web.Navigate("http://ip.qq.com/") Do Until web.ReadyState = 4 Application.DoEvents Loop Dim elems As System.Windows.Forms.HtmlElementCollection Elems = web.Document.GetElementsByTagName("Body") \'根据标签得到数据集合 Dim data As String = elems(0).InnerText Dim start As Integer = data.IndexOf("IP为") + 4 Dim ip91 As String =trim(data.SubString(start,15)) \'IP地址,最多15个字符 Dim i As Integer Dim j As String For i =8 To 15 \'IP地址至少7位 j =mid(ip91,i,1) If j=chr(10) Then ip91=mid(ip91,1,i-1) \'最终的IP地址 Exit For End If Next start = data.IndexOf("IP所在地为") + 9 Dim ip92 As String=trim(data.SubString(start,15)) \'IP地址对应的城市,最多15个字符 For i =6 To 15 \'城市最少5个字符 j =mid(ip92,i,1) If j=" " Then ip92=mid(ip92,1,i-1) \'最终的城市,忽略后面的运营商 Exit For End If Next ip91=ip91 & "|" & ip92 \'合并 msgbox(ip91) \'End If |
-- 作者:qingwuzu -- 发布时间:2015/7/9 20:37:00 -- 好了,谢谢 |