/
Default.aspx.cs
58 lines (51 loc) · 2.11 KB
/
Default.aspx.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using System;
using System.Net;
using System.Web;
using UAParser;
namespace IPCow.Website
{
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
BuildPage();
}
private void BuildPage()
{
string sIPAddress = IPnetworking.GetIP4Address();
string uaString = Request.UserAgent;
HttpBrowserCapabilities bc = Request.Browser;
string sHostName;
try
{
sHostName = Dns.GetHostEntry(IPAddress.Parse(sIPAddress)).HostName.ToString();
}
catch (Exception ex)
{
sHostName = ex.Message;
}
lblUserIP.Text = sIPAddress;
lblUserAgent.Text = uaString;
lblInfo.Text += "Hostname = <strong>" + sHostName + "</strong><br />";
try
{
var uaParser = Parser.GetDefault();
ClientInfo c = uaParser.Parse(uaString);
lblInfo.Text += "Device = <strong>" + c.Device.ToString() + "</strong><br />";
lblInfo.Text += "Operating System = <strong>" + c.OS.ToString() + "</strong><br />";
lblInfo.Text += "Web Browser = <strong>" + c.UA.ToString() + "</strong><br />";
lblInfo.Text += "Is this a robot or spider = <strong>" + c.Device.IsSpider + "</strong><br />";
}
catch (Exception ex)
{
lblInfo.Text += ex.Message;
}
lblInfo.Text += "Is this a mobile device = <strong>" + bc.IsMobileDevice + "</strong><br />";
if (bc.IsMobileDevice)
lblInfo.Text += "Mobile device information = <strong>" + bc.MobileDeviceManufacturer + " " + bc.MobileDeviceModel + "</strong><br />";
lblInfo.Text += "Is this web browser a beta version = <strong>" + bc.Beta + "</strong><br />";
lblInfo.Text += "Cookies are enabled = <strong>" + bc.Cookies + "</strong><br />";
}
}
}