In this article I will explain how to get IP Address of a Website’s server using its URL or Domain name in ASP.Net using C# and VB.Net
HTML Markup
Below I the HTML markup of the page, where I have a TextBox where user can enter the URL or domain name of the Website, a Button that will act as trigger and finally a Label to display the list of IP Addresses fetched.
Website Url: <asp:TextBox ID="txtWebsiteUrl" runat="server" Text = "www.asp.net"></asp:TextBox><br /><br />
<asp:Button ID="btnGetIP" runat="server" Text="Get IP Address" OnClick = "GetIPAddress" />
<br />
<br />
<asp:Label ID="lblIPAddress" runat="server" Text=""></asp:Label>
Namespaces
You will need to use the following namespaces
C#
VB.Net
Get IP Address of Website Server using its URL or Domain Name
Below is the code to get the IP Address of the Website Server using its URL or Domain Name. Here using the Dns.GetHostAddresses method I first fetch the IPAddress array for the website server and then convert it to string and display them in Label control.
C#
protected void GetIPAddress(object sender, EventArgs e)
{
string domain = txtWebsiteUrl.Text;
IPAddress[] ip_Addresses = Dns.GetHostAddresses(domain);
string ips = string.Empty;
foreach (IPAddress ipAddress in ip_Addresses)
{
ips += ipAddress.ToString() + "<br />";
}
lblIPAddress.Text = ips;
}
VB.Net
Protected Sub GetIPAddress(sender As Object, e As EventArgs)
Dim domain As String = txtWebsiteUrl.Text
Dim ip_Addresses As IPAddress() = Dns.GetHostAddresses(domain)
Dim ips As String = String.Empty
For Each ipAddress As IPAddress In ip_Addresses
ips += ipAddress.ToString() + "<br />"
Next
lblIPAddress.Text = ips
End Sub
Demo
Downloads