Go to: Get Local Network Information

Source: Internet
Author: User

 

This is a program that obtains all the services of the system. To simplify the program, the code is still provided on the console. You can encapsulate the desired functions in addition.

Core code:

Using system;
Using system. Collections. Generic;
Using system. Data. SQL;
Using system. net;
Using system. net. networkinformation;

Namespace allsqlserver
{
Class Program
{
Static void main (string [] ARGs)
{
Shownetworkinterfaces ();

Console. Readline ();
}

Public static void shownetworkinterfaces ()
{
Ipglobalproperties computerproperties = ipglobalproperties. getipglobalproperties ();
Networkinterface [] interfaces = networkinterface. getallnetworkinterfaces ();
Console. writeline ("interface information for {0}. {1 }",
Computerproperties. hostname, computerproperties. domainname );
If (Bytes = NULL | bytes. Length <1)
{
Console. writeline ("No network interfaces found .");
Return;
}

Console. writeline ("number of interfaces ......: {0}", response. Length );
Foreach (networkinterface adapter in progress)
{
Ipinterfaceproperties properties = Adapter. getipproperties ();
Console. writeline ();
Console. writeline (adapter. Description );
Console. writeline (string. Empty. padleft (adapter. description. length, '= '));
Console. writeline ("network type ..........................: {0} ", adapter. networkinterfacetype );
Console. writeline ("MAC address...: {0 }",
Adapter. getphysicaladdress (). tostring ());
Console. writeline ("operational status ......: {0 }",
Adapter. operationalstatus );
String versions = "";

If (adapter. Supports (networkinterfacecomponent. IPv4 ))
{
Versions = "IPv4 ";
}
If (adapter. Supports (networkinterfacecomponent. IPv6 ))
{
If (versions. length> 0)
{
Versions + = "";
}
Versions + = "IPv6 ";
}
Console. writeline ("IP version ..............................: {0} ", versions );
Showipaddresses (properties );

If (adapter. networkinterfacetype = networkinterfacetype. loopback)
{
Continue;
}
Console. writeline ("DNS suffix ..............................: {0 }",
Properties. dnssuffix );

String label;
If (adapter. Supports (networkinterfacecomponent. IPv4 ))
{
Ipv4interfaceproperties IPv4 = properties. getipv4properties ();
Console. writeline ("MTU .................................... ..: {0} ", ipv4.mtu );
If (ipv4.useswins)
{

Ipaddresscollection winsservers = properties. winsserversaddresses;
If (winsservers. Count> 0)
{
Label = "WINS servers ............................:";
Showipaddresses (Label, winsservers );
}
}
}

Console. writeline ("whether it is configured as a Domain Name System (DNS) query the server sending name resolution :.............................: {0 }",
Properties. isdnsenabled );
Console. writeline ("is configured to automatically register its IP address information with the Domain Name System (DNS :..............: {0 }",
Properties. isdynamicdnsenabled );
Console. writeline ("receive only ............................: {0 }",
Adapter. isreceiveonly );
Console. writeline ("Multicast ...............................: {0 }",
Adapter. supportsmulticast );

Console. writeline ();
}
}

Private Static void showipaddresses (ipinterfaceproperties properties)
{
Console. writeline ("DHCP server address :");
Showipaddresscollection (properties. dhcpserveraddresses );
Console. writeline ("DNS server :");
Showipaddresscollection (properties. dnsaddresses );
Console. writeline ("Gateway :");
Showgatewayipaddressinformationcollection (properties. gatewayaddresses );
Console. writeline ("is configured to send name resolution query to the Domain Name System (DNS) server:" + properties. isdnsenabled. tostring ());
Console. writeline ("is configured to automatically register its IP address information with the Domain Name System (DNS):" + properties. isdynamicdnsenabled. tostring ());
Console. writeline ("multicast address assigned to this interface :");
Showmulticastipaddressinformationcollection (properties. multicastaddresses );
Console. writeline ("Address of the Windows Internet Name Service (WINS) server :");
Showipaddresscollection (properties. winsserversaddresses );
}

Private Static void showipaddresses (string label, ipaddresscollection winsservers)
{
Console. writeline ("-----" + label + "-----");
Showipaddresscollection (winsservers );
}

Private Static void showipaddressinformationcollection (ipaddressinformationcollection collection)
{
For (INT I = 0; I <collection. Count; I ++)
{
Console. writeline (getipaddressinfo (Collection [I]. Address ));
}
}

Private Static void showipaddresscollection (ipaddresscollection collection)
{
For (INT I = 0; I <collection. Count; I ++)
{
Console. writeline (getipaddressinfo (Collection [I]);
}
}

Private Static void showmulticastipaddressinformationcollection (multicastipaddressinformationcollection collection)
{
For (INT I = 0; I <collection. Count; I ++)
{
Console. writeline (getipaddressinfo (Collection [I]. Address ));
}
}

Private Static string getipaddressinfo (IPaddress address)
{
Byte [] bytes = address. getaddressbytes ();
String ipstring = NULL;
For (INT I = 0; I <bytes. Length-1; I ++)
{
Ipstring + = bytes [I] + ".";
}
Return ipstring + bytes [bytes. Length-1];
}

Private Static void showgatewayipaddressinformationcollection (gatewayipaddressinformationcollection collection)
{
For (INT I = 0; I <collection. Count; I ++)
{
Console. writeline (getipaddressinfo (Collection [I]. Address ));
}
}
}
}

The execution result on my local machine is as follows:
Interface Information for zhoufoxcn. sooyie
Number of interfaces ......

NVIDIA nforce networking Controller
==========================================
Network type...
MAC address ......: 003018adb71c
Operational Status ......
IP version...
DHCP server address:
255.255.255.255
DNS Server:
192.168.3.3
202.99.192.66
Gateway:
192.168.3.1
Whether it is configured to send name resolution query to the Domain Name System (DNS) server: false
Whether it is configured to automatically register its IP address information with the Domain Name System (DNS): True
The multicast address assigned to this interface:
224.0.0.1
Windows Internet Name Service (WINS) server address:
0.0.0.0
0.0.0.0
DNS suffix ..............................:
MTU ...................................... 1500
Is it configured to the Domain Name System (DNS) query the server sending name resolution :...........................
...: False
Whether the domain name is configured to automatically register its IP address information with the Domain Name System (DNS): ...... true
Receive only ......: false
Multicast ......................: True

TCP loopback interface of MS
======================================
Network type...
MAC address ........................:
Operational Status ......
IP version...
DHCP server address:
DNS Server:
Gateway:
Whether it is configured to send name resolution query to the Domain Name System (DNS) server: false
Whether it is configured to automatically register its IP address information with the Domain Name System (DNS): True
The multicast address assigned to this interface:
224.0.0.1
Windows Internet Name Service (WINS) server address:

Turn: http://blog.csdn.net/zhoufoxcn/archive/2007/05/29/1630123.aspx

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.