• We just launched and are currently in beta. Join us as we build and grow the community.

Converting domain names to IP addresses

UsernameOLD

Crypto Attack Strategist
U Rep
0
0
0
Rep
0
U Vouches
0
0
0
Vouches
0
Posts
148
Likes
137
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 300 XP
Submitted by
planetsourcecode

on
Tue, 06/09/2009 - 13:03

In ASP.NET, we can easily convert the Domain names to its related IP address like if a website like planetsourcecode.in has a domain name i.e planetsourcecode.com, It has also a corresponding Internet Protocol Address like 208.111.14.112.
this can be easily done in ASP.NET using C#

Steps for doing this:
1). First we have to include the namespace for this class

Using System.net;

2). Second include two textbox,one command button and Label as below
1--> txtDomain, textbox, to enter the domain names
2--> txtIPs, textbox, to get the desired IP address
3--> btnSubmit, button
4--> lblStatus,Label, for successful result

3). Double click on the command buttton and write the following in cod behind

DNSLookup(txtDomain.Text);

4). and write a method to do this work

protected void DNSLookup(string domain)
{
try
{
//performs the DNS lookup
IPHostEntry he = Dns.GetHostByName(domain);
IPAddress[] ip_addrs = he.AddressList;
txtIPs.Text = "";
foreach (IPAddress ip in ip_addrs)
{
txtIPs.Text += ip + "\n";
}
}
catch (System.Exception ex)
{
lblStatus.Text = ex.ToString();
}
}

Default.aspx

%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

Domain Name:

IP Address(es)

Default.aspx.cs

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
DNSLookup(txtDomain.Text);
}
protected void DNSLookup(string domain)
{
try
{
//performs the DNS lookup
IPHostEntry he = Dns.GetHostByName(domain);
IPAddress[] ip_addrs = he.AddressList;
txtIPs.Text = "";
foreach (IPAddress ip in ip_addrs)
{
txtIPs.Text += ip + "\n";
}
}
catch (System.Exception ex)
{
lblStatus.Text = ex.ToString();
}
}
}

About the author:

Planet Source Code is a place for all developer providing free source codes, articles, complete projects,complete application in PHP, C/C++, Javascript, Visual Basic, Cobol, Pascal, ASP/VBScript, AJAX, SQL, Perl, Python, Ruby, Mobile Development

 

452,496

335,256

335,264

Top