2011-08-14 86 views
1
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 端功能真實網站上的WebSite 503錯誤?

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) 

專此代碼

回答

1

我的猜測是,whatismyipaddress.com可能有從做正是你在做什麼,在採取措施,試圖擋人。

他們正在返回503意味着「服務不可用」。

如果您確定自己應該能夠使用bot來抓取他們的網站,那麼您需要聯繫whatismyaddress.com的管理員以獲取幫助。

你的代碼的另一個問題是,你看起來你只需點擊一次按鈕就可以獲取他們的頁面8次,這可能不是一個好的禮儀(除非你知道WC.DownloadString緩存響應,我猜)。

+0

這就是我一次打8次的事實。該網站不喜歡這樣,我解決它和使用:Public Sub GetSiteSource(ByVal IPNumb As String) Dim URL As String =「http://whatismyipaddress.com/ip/」&IPNumb 昏暗的客戶端作爲System.Net。 WebClient = New System.Net.WebClient() Dim data As System.IO.Stream = client.OpenRead(URL) Dim reader As System.IO.StreamReader = New System.IO.StreamReader(data) IPCheckWebsite = reader。 ReadToEnd End Sub instead – SirAudens

+0

註釋不保存代碼? – SirAudens

+0

你可以把''這樣的代碼反引號'。 – thomasrutter