01.
sing System;
02.
using
System.Data;
03.
using
System.Configuration;
04.
using
System.Collections;
05.
using
System.Web;
06.
using
System.Web.Security;
07.
using
System.Web.UI;
08.
using
System.Web.UI.WebControls;
09.
using
System.Web.UI.WebControls.WebParts;
10.
using
System.Web.UI.HtmlControls;
11.
using
System.Management;
12.
using
System.Net;
13.
14.
15.
protected
void
Page_Load(
object
sender, EventArgs e)
16.
{
17.
string
msg ;
18.
ManagementObjectSearcher query =
new
ManagementObjectSearcher(
"select * from Win32_NetworkAdapterConfiguration WHERE IPEnabled = 'TRUE' "
);
19.
20.
ManagementObjectCollection queryCollection = query.Get();
21.
foreach
(ManagementObject mo
in
queryCollection)
22.
{
23.
24.
string
[] addresses = (
string
[])mo[
"IPAddress"
];
25.
string
[] subnets = (
string
[])mo[
"IPSubnet"
];
26.
string
[] defaultgateways = (
string
[])mo[
"DefaultIPGateway"
];
27.
msg=
"<br>HostName = "
+ mo[
"DNSHostName"
];
28.
msg=msg+
"<br>Network Card: "
+ mo[
"Description"
];
29.
msg=msg+
"<br>Mac Address : "
+ mo[
"MACAddress"
];
30.
31.
32.
foreach
(
string
ipaddress
in
addresses)
33.
{
34.
msg = msg +
"<br>IP Address : "
+ ipaddress;
35.
}
36.
foreach
(
string
subnet
in
subnets)
37.
{
38.
msg = msg +
"<br>Subnet Mark : "
+ subnet;
39.
}
40.
foreach
(
string
defaultgateway
in
defaultgateways)
41.
{
42.
msg = msg +
"<br>Gateway : "
+ defaultgateway;
43.
44.
}
45.
Literal1.Text = msg.ToString();
46.
}
47.
48.
}