How to get the host's IP address address

xiaoxiao2021-03-06  110

http://www.aspcn.com flying knife

(For reprint, please indicate the article from http://www.aspcn.com Thank you for your cooperation)

This article, we don't prepare a large-scale discussion technical issue. Just telling you how we will get an IP address of a host. In the Win32 API we can use the Network API to complete this work, but how should we do under the .NET platform? In fact, however, the method of operation is almost like API, but everyone must understand Namespace and Class. There are a lot of articles in this site, and the contents of Namespace and Class are not introduced.

The .NET platform has a System.net namespace, where the DNS class provides some ways to get the servers' service name or an IP address. DNS is a static class, so it can create class instances directly. Gossip less, let's see specific procedures:

Namespace nkutilities {using system.net; public class dnsutility {public static int main (string "args) {string strHostname = new string (" "); if (args.length == 0) {// Get a local IP address // First, the host name of the local machine strHostName = DNS.GETHOSTNAME (); Console.writeline ("local machine's host name: strHostname);} else {strhostname = args [0];} // then Using the host name, get the IP address list // One host may not only one IP, don't be misleaded by some people, huh, I think about the previous 163 and 169, I know iphostentry ipentry = dns.gethostbyName (strHostname); ipaddress [] addr = ipentry.addresslist; for (int i = 0; i

转载请注明原文地址:https://www.9cbs.com/read-100092.html

New Post(0)