c#

位置:IT落伍者 >> c# >> 浏览文章

C#中如何得到主机名与IP地址


发布日期:2023年07月20日
 
C#中如何得到主机名与IP地址

/*

* Copyright (c) 四川师范大学

* All rights reserved

* 文件名称GetIpAndName

* 文件标识见配置管理计划书

* 文件摘要得到本地主机的名字与IP

*/

using System;

using SystemNet;

/*

* 当前版本

* 软件作者安美洪

* 完成日期

*

* 取代版本

* 原作者

* 完成日期

*/

namespace GetIpAndName

{

class Class

{

[STAThread]

static void Main(string[] args)

{

//得到主机名

string name = DnsGetHostName();

ConsoleWriteLine(主机名字{}name);

IPHostEntry me = DnsGetHostByName(name);

//输出得到的IP

foreach (IPAddress ip in meAddressList)

{

ConsoleWriteLine(IP 地址{}ipToString());

}

ConsoleRead();

}

}

}

               

上一篇:使用.NET 向浏览器写入二进制文件

下一篇:ADO.NET读书笔记系列