Support Forums

Full Version: [Source] Hostname To IP
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Another simple source to share.

Screenshot:
[Image: huqgU.jpg]

Full Codes:
Code:
Imports System.Net
Imports System.Text.RegularExpressions

Public Class Form1

    Private Sub ButtonGetIP_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonGetIP.Click
        TextBoxHostIP.Text = getip(TextBoxHostname.Text)
    End Sub

    Private Function getip(ByVal hostname As String) As String
        Try
            Dim postData As String = "url=" & hostname & "&submit=Get+IP"

            Dim encoding As New System.Text.UTF8Encoding
            Dim byteData As Byte() = encoding.GetBytes(postData)

            Dim host = "http://www.selfseo.com/find_ip_address_of_a_website.php"
            Dim postReq As HttpWebRequest = DirectCast(WebRequest.Create(host), HttpWebRequest)
            postReq.Method = "POST"
            postReq.KeepAlive = True
            postReq.ContentType = "application/x-www-form-urlencoded"
            postReq.Referer = host
            postReq.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; ru; rv:1.9.2.3) Gecko/20100401 Firefox/4.0 (.NET CLR 3.5.30729)"
            postReq.ContentLength = byteData.Length

            Dim postreqstream As IO.Stream = postReq.GetRequestStream()
            postreqstream.Write(byteData, 0, byteData.Length)
            postreqstream.Close()

            Dim postresponse As HttpWebResponse = DirectCast(postReq.GetResponse(), HttpWebResponse)
            Using postreqreader As New IO.StreamReader(postresponse.GetResponseStream())
                Dim thepage As String = postreqreader.ReadToEnd

                Dim o As Match = Regex.Match(thepage, "The IP address (\S+) is assigned to", _
                                          RegexOptions.IgnoreCase)
                If (o.Success) Then
                    Dim key As String = o.Groups(1).Value
                    Return key
                Else
                    MsgBox("Error: Please check your hostname.", MsgBoxStyle.Exclamation, "Message")
                End If
            End Using
        Catch ex As Exception
            MsgBox("Error: " & ex.Message, MsgBoxStyle.Exclamation, "Message")
        End Try
    End Function
End Class
You should use MessageBox.Show instead of MsgBox euverve Smile

Also maybe a With statement?
Code:
With postReq
    .Method = "POST"
    .KeepAlive = True
    .ContentType = "application/x-www-form-urlencoded"
    .Referer = host
    .UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; ru; rv:1.9.2.3) Gecko/20100401 Firefox/4.0 (.NET CLR 3.5.30729)"
    .ContentLength = byteData.Length
End With

Otherwise not bad Smile
Thanks for posting the source i really needed this.
Thanks for posting that it helpd me a lot.
Thanks for this, i remember that site. i was nearly a moderator on it Big Grin
Yet another DNS to IP application. You should progress further with this to make it stand out from the rest.