Get IP Address and Hostname using Visual Basic and Asp.Net
Posted by Samath
Last Updated: March 29, 2015

This is a simple program that fetch the IP Address of a system using the hostname. The program could be modify to fetch the IP address of any host. What it basically does is use the DNS class in the .Net Framework to get the info.

The Dns class is a static class that retrieves information about a specific host from the Internet Domain Name System (DNS).

so for example instead of doing what I did below in the example, you could get the IP address of a website by passing in the website name as argument instead of the local host name.


<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="">
<head runat="server">
    <title>Untitled Page</title>
    <style type="text/css">
        .auto-style1 {
            width: 100%;
            vertical-align: top;
    <form id="form1" runat="server">
    <div style="width: 278px">

        <table class="auto-style1" align="left">
                    <asp:Label ID="Label1" runat="server" Text="Host Name: "></asp:Label>
                    <asp:Label ID="lblhostname" runat="server" Text="Label"></asp:Label>
                    <asp:Label ID="Label4"  runat="server" Text="IP Address: "></asp:Label>
                    <asp:ListBox ID="lstipaddress" runat="server"></asp:ListBox>
        <asp:Button ID="btngetip" runat="server" Text="Get IP Address and Host Name" />



.vb code:

Imports System.Data
Imports System.Net

Partial Class _Default
    Inherits System.Web.UI.Page

    Protected Sub btngetip_Click(sender As Object, e As EventArgs) Handles btngetip.Click
        Dim host_name As String
        Dim i As System.Net.IPHostEntry
        host_name = System.Net.Dns.GetHostName
        i = System.Net.Dns.GetHostByName(host_name)

        lblhostname.Text = i.HostName

        For Each b As System.Net.IPAddress In i.AddressList

    End Sub
End Class



Hmmm not a bad...not a bad my boy
Must say its quite handy