Support Forums
[Source] Hostname To IP - Printable Version

+- Support Forums (https://www.supportforums.net)
+-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87)
+--- Forum: Coding Support Forums (https://www.supportforums.net/forumdisplay.php?fid=18)
+---- Forum: Visual Basic and the .NET Framework (https://www.supportforums.net/forumdisplay.php?fid=19)
+---- Thread: [Source] Hostname To IP (/showthread.php?tid=24842)



[Source] Hostname To IP - euverve - 01-27-2012

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



RE: [Source] Hostname To IP - AceInfinity - 01-27-2012

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


RE: [Source] Hostname To IP - TwoMuchCaffeine - 01-27-2012

Thanks for posting the source i really needed this.


RE: [Source] Hostname To IP - zoogo - 01-29-2012

Thanks for posting that it helpd me a lot.


RE: [Source] Hostname To IP - Denny Crane - 02-04-2012

Thanks for this, i remember that site. i was nearly a moderator on it Big Grin


RE: [Source] Hostname To IP - OnyxDev - 05-15-2012

Yet another DNS to IP application. You should progress further with this to make it stand out from the rest.