1
.NET Framework / Re: [C#] LocateIP 0.2
« on: January 30, 2016, 11:44:36 pm »
Wow great work. i really admire your work doddy. anyway i also made mine. simple and short code.
Screenshot:
Source Code:
Screenshot:
Source Code:
Code: [Select]
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Net;
using System.Text;
using System.Windows.Forms;
using System.Xml;
/* <copyright file=xfrmMaim>
Copyright (c) 2016 All Rights Reserved
</copyright>
<author>h4nn1b4L</author>
<date>1/31/2016 6:26AM</date>
<summary>Simple and Short Ip Tracer Code on c#</summary>*/
namespace TraceIP
{
public partial class xfrmMain : Form
{
private IpInfo Info = new IpInfo();
public xfrmMain()
{
InitializeComponent();
}
private void btnSearch_Click(object sender, EventArgs e)
{
Invoke((MethodInvoker)delegate
{
Parse(txtIpaddress.Text);
});
}
private class IpInfo
{
public string CountryName { get; set; }
public string RegionName { get; set; }
public string City { get; set; }
public double Latitude { get; set; }
public double Longitude { get; set; }
}
private void Parse(string ip)
{
try
{
string url = "http://freegeoip.net/xml/";
string furl = url + ip;
XmlDocument doc = new XmlDocument();
doc.Load(furl);
XmlElement root = doc.DocumentElement;
XmlNode node = root.SelectSingleNode("/Response");
Info.CountryName = node["CountryName"].InnerText;
Info.RegionName = node["RegionName"].InnerText;
Info.City = node["City"].InnerText;
Info.Latitude = Convert.ToDouble(node["Latitude"].InnerText);
Info.Longitude = Convert.ToDouble(node["Longitude"].InnerText);
LoadData();
}
catch (Exception ex)
{
MessageBox.Show("Error: " + ex.Message);
}
}
private void LoadData()
{
txtCountry.Text = Info.CountryName;
txtCity.Text = Info.City;
txtRegion.Text = Info.RegionName;
txtLat.Text = Info.Latitude.ToString();
txtLng.Text = Info.Longitude.ToString();
}
}
}