首页 > 代码库 > C#网络编程学习_01
C#网络编程学习_01
参考http://blog.csdn.net/yuzhongchun/article/details/11990571
using System.Net;namespace Network_01{ public partial class Main : Form { public Main() { InitializeComponent(); } private void btnGetHostName_Click(object sender, EventArgs e) { DebugInfo.Text = Dns.GetHostName();//返回本机名称 } private void btnGetHostEntry_Click(object sender, EventArgs e) { DebugInfo.Text = ""; IPHostEntry ipEntry = Dns.GetHostEntry(Dns.GetHostName()); //返回目标主机实例 foreach (IPAddress ipAddr in ipEntry.AddressList) { if (ipAddr.AddressFamily.ToString() == "InterNetwork") //IP4 InterNetworkV6 IP6 DebugInfo.Text += ipAddr.AddressFamily.ToString()+":" + ipAddr.ToString() + "\r\n"; } } private void WebGetHostEntry_Click(object sender, EventArgs e) { DebugInfo.Text = ""; IPHostEntry ipEntry = Dns.GetHostEntry(AddrText.Text.Trim()); foreach (IPAddress ipAddr in ipEntry.AddressList) { if (ipAddr.AddressFamily.ToString() == "InterNetwork") //IP4 DebugInfo.Text += ipAddr.AddressFamily.ToString() + ":" + ipAddr.ToString() + "\r\n"; } } }}
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。