Game Master Hacker Game Master Hacker - 9 months ago 49
C# Question

How can I acquire IP addresses of users that visit my websites using html agility pack?

I am using a combo box, two buttons (one to extract, other to clear DGV), and a data grid view with various columns(15) However; right now I am only concerned with two (IPAddress & TimeStamp). The code is meant to extract the data using html agility pack to scrape it off a secure web hosting site (like Host Gator, Go Daddy or Blue Host). how can I authenticate login credentials and extract? The code below is about as far as I got before running into logic issues. I have tried using http web request and stream reader to authenticate but, that didn't seem to work. Now i'm a little lost.

public partial class Lead_Tracker : Form
{
DataTable IP_Table;
HtmlWeb Web = new HtmlWeb();
string url;

public Lead_Tracker()
{
InitializeComponent();
InitIPTable();
}

public class DataPile
{
public string IPAddress { get; set; }
public string TimeStamp { get; set; }
public string CountryCode { get; set; }
public string CountryName { get; set; }
public string RegionCode { get; set; }
public string Region { get; set; }
public string CityCode { get; set; }
public string CityName { get; set; }
public string ISP { get; set; }
public string Organization { get; set; }
public string Latitude { get; set; }
public string Longitude { get; set; }
public string ZipCode { get; set; }
public string TimeZone { get; set; }
}

private void InitIPTable()
{
IP_Table = new DataTable("IPDataGridTable");
IP_Table.Columns.Add("IP Address", typeof(string));
IP_Table.Columns.Add("Timestamp", typeof(string));
IP_DataGridView.DataSource = IP_Table;
}

private async Task<List<DataPile>> DataGridOutput()
{
if (WS_ComboBox.SelectedIndex < 0)
{
MessageBox.Show("Please Select a Website Before Tracking.");
IP_Table.Rows.Clear();
return new List<DataPile>();
}

if (WS_ComboBox.SelectedIndex == 0)
{
url="www.firstwebsite.com";
}

var doc = await Task.Factory.StartNew(() => Web.Load(url));
var IPNode = doc.DocumentNode.SelectNodes("//td[@class='pagecode']");
var TimeStampNode = doc.DocumentNode.SelectNodes("//td[@class='pagecode']");


// If these are null it means that the information could not be found at the website
if (IPNode == null || TimeStampNode == null)

return new List<DataPile>();

var IPs = IPNode.Select(Node => Node.InnerText);
var TimeStamps = TimeStampNode.Select(Node => Node.InnerText);
var IPData = IPs.Zip(TimeStamps, (ip, timestamps) => new DataPile() {IPAddress = ip, TimeStamp = timestamps }).ToList();

return IPData;
}

private void Lead_Tracker_Load(object sender, EventArgs e)
{

}

private async void IP_Btn_Click(object sender, EventArgs e)
{
var DataGridSource = await DataGridOutput();

foreach (var Info in DataGridSource)
{
IP_Table.Rows.Add(Info.IPAddress, Info.TimeStamp);
DataGridSource = await DataGridOutput();
}

return;

}

private void IP_DataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
//button to get the individual locations of the IP address within the row
}

private void Clear_Btn_Click(object sender, EventArgs e)
{
IP_DataGridView.Rows.Clear();
}
}

Answer Source

If we are talking about users that are not using your software, it is not possible to obtain the IP addresses of users accessing a web site you do not own without doing something nefarious, e.g. installing malware on each of their machines.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download