zoukankan      html  css  js  c++  java
  • TCP编程(1):获得IP地址及域名

    /*--===------------------------------------------===---
    测试DNS类,实现IP地址和域名之间的转换

                许明会    12:25:29 2007年12月9日
    --===------------------------------------------===---
    */
    using System;
    using System.Net; //引入Net空间

    namespace xumh
    {
        
    public class myClass
        {
        };

        
    public class runMyApp
        {
            
    static void Main()
            {
                
    string strLocalHost=Dns.GetHostName();
                IPHostEntry he 
    = Dns.GetHostEntry(strLocalHost);
                Console.Write(
    "本机主机名称为{0},IP地址为{1}",
                    strLocalHost, he.AddressList[
    0].ToString());
                
    //根据IP地址得到域名
                Console.WriteLine("请输入IP地址,得到其域名:");
                
    string strIP = Console.ReadLine();
                he 
    = Dns.GetHostEntry(strIP);
                Console.WriteLine(
    "{0},{1}",strIP,he.HostName);
                
    //根据域名得到IP地址
                Console.Write("请输入域名,得到其IP地址:");
                
    string strDomain = Console.ReadLine();
                he 
    = Dns.GetHostEntry(strDomain);
                Console.WriteLine(
    "{0},{1}",strDomain,he.AddressList[0].ToString());

            }
        };
    }
  • 相关阅读:
    Code review
    一点心得
    有关双向追踪性的一点感觉
    测试用例分析的一点心得
    js简单的抽屉菜单
    新的感受
    linux的VPS如何分区
    PHP中Unicode转码和解码的实现
    xampp安装及配置
    js Unicode编码转换
  • 原文地址:https://www.cnblogs.com/flaaash/p/988741.html
Copyright © 2011-2022 走看看