Public Function GetIPInfo(ByVal IPNumb As String, ByVal GetInfo As String) As String
Dim i1, i2 As Integer
Dim s1, s2, s3 As String
Dim IPCheckWebsite As String
Dim WC As System.Net.WebClient = New System.Net.WebClient()
IPCheckWebsite = WC.DownloadString("http://whatismyipaddress.com/ip/" & IPNumb)
For i1 = 1 To Len(IPCheckWebsite)
s1 = Mid(IPCheckWebsite, 1, i1)
If InStr(s1, GetInfo) > 0 Then
s2 = Mid(IPCheckWebsite, i1 + 10)
For i2 = 1 To Len(s2)
s3 = Mid(s2, 1, i2)
If InStr(s3, "<") > 0 Then
IPCheckWebsite = Mid(s3, 1, i2 - 1)
GoTo Done
End If
Next
End If
Next
完成: 返回IPCheckWebsite 结束功能
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ListBox1.Items.Clear()
ListBox1.Items.Add("IP: " & GetIPInfo(TextBox3.Text, "IP:"))
ListBox1.Items.Add("Hostname: " & GetIPInfo(TextBox3.Text, "Hostname:"))
ListBox1.Items.Add("ISP: " & GetIPInfo(TextBox3.Text, "ISP:"))
ListBox1.Items.Add("Organization: " & GetIPInfo(TextBox3.Text, "Organization:"))
ListBox1.Items.Add("Services: " & GetIPInfo(TextBox3.Text, "Services:"))
ListBox1.Items.Add("Country: " & GetIPInfo(TextBox3.Text, "Country:"))
ListBox1.Items.Add("State/Region: " & GetIPInfo(TextBox3.Text, "State/Region:"))
ListBox1.Items.Add("City: " & GetIPInfo(TextBox3.Text, "City:"))
End Sub
它说网站服务器有503错误,但该网站已启动并正常工作。我做错了吗?
Dim WC As System.Net.WebClient = New System.Net.WebClient()
IPCheckWebsite = WC.DownloadString("http://whatismyipaddress.com/ip/" & IPNumb)
具体来说这段代码
答案 0 :(得分:1)
我的猜测是,whatismyipaddress.com可能已采取措施阻止人们正在做你正在做的事情。
他们正在返回503响应,这意味着“服务不可用”。
如果您确定应该能够使用机器人刮取他们的网站,您需要联系whatismyaddress.com的管理员以获取他们的帮助。
您的代码的另一个问题是,如果单击一次按钮就会显示您的页面被抓取8次,这可能不是很好的礼仪(除非您知道WC.DownloadString正在缓存响应,我猜)。