It is also very effective to directly call the system IPCONFIG when we obtain the local lan ip address and other related information.
The following code reads the returned values of ipconfig using C:
01
/// <summary>
02
/// Obtain the IPCONFIG Return Value
03
/// </summary>
04
/// <Returns> return IPCONFIG output </returns>
05
public
static
string
GetIPConfigReturns()
06
{
07
string
version = System.Environment.OSVersion.VersionString;
08
09
if
(version.Contains(
"Windows"
))
10
{
11
// Call ipconfig and input the parameter:/all
12
System.Diagnostics.ProcessStartInfo psi =
new
System.Diagnostics.ProcessStartInfo(
"ipconfig"
,
"/all"
);
13
14
psi.CreateNoWindow =
true
;
// If it is false, the cmd black form will appear.
15
psi.RedirectStandardOutput =
true
;
16
psi.UseShellExecute =
false
;
17
18
System.Diagnostics.Process p = System.Diagnostics.Process.Start(psi);
19
20
return
p.StandardOutput.ReadToEnd();
21
}
22
23
return
string
.Empty;
24
}
The returned results are as follows: