01.
using
System;
02.
using
System.Collections.Generic;
03.
using
System.Diagnostics;
04.
using
System.Linq;
05.
using
System.Net;
06.
using
System.Net.NetworkInformation;
07.
using
System.Net.Sockets;
08.
using
System.Threading;
09.
10.
namespace
ConsoleApp1
11.
{
12.
class
Program
13.
{
14.
static
void
Main(
string
[] args)
15.
{
16.
foreach
(IPAddress ip
in
Dns.GetHostEntry(
"192.168.1.108"
).AddressList)
17.
{
18.
if
(ip.AddressFamily.ToString() ==
"InterNetwork"
)
19.
{
20.
Console.WriteLine(ip.ToString());
21.
}
22.
}
23.
}
24.
25.
static
IPAddress NetworkGateway()
26.
{
27.
IPAddress ip =
null
;
28.
29.
foreach
(NetworkInterface f
in
NetworkInterface.GetAllNetworkInterfaces())
30.
{
31.
if
(f.OperationalStatus == OperationalStatus.Up)
32.
{
33.
foreach
(GatewayIPAddressInformation d
in
f.GetIPProperties().GatewayAddresses)
34.
{
35.
ip = d.Address;
36.
}
37.
}
38.
}
39.
40.
return
ip;
41.
}
42.
}
43.
}