An IP address is a fascinating
product of modern computer technology designed to allow one computer (or other
digital device) to communicate with another via the Internet. IP addresses
allow the location of literally billions of digital devices that are connected
to the Internet to be pinpointed and differentiated from other devices. In the
same sense that someone needs your mailing address to send you a letter, a
remote computer needs your IP address to communicate with your computer.
An IP address consists of four
numbers, each of which contains one to three digits, with a single dot (.)
separating each number or set of digits. Each of the four numbers can range
from 0 to 255.
Your IP address is something you
probably rarely think about, but it's vitally important to your online
lifestyle. Without an IP address, you wouldn't be able to get today's weather,
check the latest news or look at videos online. So we can Store our client
IPAddress we he/she visits our Site or Application.
In this Example we will see how
to get Address Details using IPAddress.
HTML CODE:-
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<table cellpadding="0" cellspacing="0" width="50%" align="center" style="background-color: #f5f5f5; color: #4f6b72;">
<tr>
<td align="center">
<asp:Panel ID="panelLoc" runat="server" Style="text-align:center">
<ContentTemplate>
<asp:Label ID="Label2" runat="server"
Text="Details of
Client IP Address" Font-Bold="False" Font-Names="Monotype Corsiva" Font-Size="X-Large" Font-Underline="True"></asp:Label>
<br />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<br />
<asp:Xml ID="Xml1" runat="server"></asp:Xml>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdateProgress ID="updProgress"
AssociatedUpdatePanelID="UpdatePanel1"
runat="server">
<ProgressTemplate>
<img alt="progress" src="Image.gif" style="height: 31px; width: 49px" />
</ProgressTemplate>
</asp:UpdateProgress>
</td>
</tr>
</table>
</div>
CODE BEHIND:-
public void bind()
{
WebClient
wc = new WebClient();
Stream
data = wc.OpenRead("http://ip-api.com/xml/");
String
str;
using (StreamReader sr = new
StreamReader(data))
{
string strReturnVal;
str = sr.ReadToEnd();
Console.WriteLine(@"Xml.Linq =
obRoot.Elements(""query"")");
XElement
obRoot = XElement.Parse(str);
XmlDocument
xmldoc = new XmlDocument();
xmldoc.LoadXml(str);
data.Close();
XmlNodeList
responseXML = xmldoc.GetElementsByTagName("query");
NameValueCollection
dataXML = new NameValueCollection();
dataXML.Add(responseXML.Item(0).ChildNodes[2].InnerText,
responseXML.Item(0).ChildNodes[2].Value);
strReturnVal = "Contry : " + responseXML.Item(0).ChildNodes[1].InnerText.ToString()
+ "<hr/>";// Contry
strReturnVal += "ContryCode : " + "(" +
responseXML.Item(0).ChildNodes[2].InnerText.ToString() + ")" + "<hr/>";// ContryCode
strReturnVal += "region :" + "("
+ responseXML.Item(0).ChildNodes[3].InnerText.ToString() + ")" + "<hr/>";//region
strReturnVal += "regionName : " + "(" +
responseXML.Item(0).ChildNodes[4].InnerText.ToString() + ")" + "<hr/>";//regionName
strReturnVal += "City : " + "("
+ responseXML.Item(0).ChildNodes[5].InnerText.ToString() + ")" + "<hr/>";//City
strReturnVal += "Zip Code : " + "("
+ responseXML.Item(0).ChildNodes[6].InnerText.ToString() + ")" + "<hr/>";//Zip
strReturnVal += "Latitude : " + "("
+ responseXML.Item(0).ChildNodes[7].InnerText.ToString() + ")" + "<hr/>";//lat
strReturnVal += "Longitude : " + "(" +
responseXML.Item(0).ChildNodes[8].InnerText.ToString() + ")" + "<hr/>";//lon
strReturnVal += "Timezone : " + "("
+ responseXML.Item(0).ChildNodes[9].InnerText.ToString() + ")" + "<hr/>";//timezone
strReturnVal += "ISP : " + "("
+ responseXML.Item(0).ChildNodes[10].InnerText.ToString() + ")" + "<hr/>";//isp
strReturnVal += "Organization : " + "(" +
responseXML.Item(0).ChildNodes[11].InnerText.ToString() + ")" + "<hr/>";//org
strReturnVal += "AS : " + "("
+ responseXML.Item(0).ChildNodes[12].InnerText.ToString() + ")" + "<hr/>";//as
strReturnVal += "Query : " + "("
+ responseXML.Item(0).ChildNodes[13].InnerText.ToString() + ")";//query
Label1.Text =
strReturnVal;
}
}
Run your Web
Application you web get Client Address Details Using IP Address.
Thanks for comments.....