c# 获取本机ip.doc
上传人:yy****24 上传时间:2024-09-10 格式:DOC 页数:2 大小:35KB 金币:16 举报 版权申诉
预览加载中,请您耐心等待几秒...

c# 获取本机ip.doc

c#获取本机ip.doc

预览

在线预览结束,喜欢就下载吧,查找使用更方便

16 金币

下载此文档

如果您无法下载资料,请参考说明:

1、部分资料下载需要金币,请确保您的账户上有足够的金币

2、已购买过的文档,再次下载不重复扣费

3、资料包下载后请先用软件解压,在使用对应软件打开

usingSystem.Net;//方法一:stringstrHostIP="";IPHostEntryoIPHost=Dns.Resolve(Environment.MachineName);if(oIPHost.AddressList.Length>0)strHostIP=oIPHost.AddressList[0].ToString();//方法二:stringip=Dns.GetHostEntry(Dns.GetHostName()).AddressList[0].ToString();///完整版本UsingSystem;UsingSystem.Drawing;usingSystem.Collections;usingSystem.ComponentModel;usingSystem.Windows.Forms;usingSystem.Data;usingSystem.Net;namespaceNetwork{///<summary>///Form1的摘要说明。///</summary>publicclassForm1:System.Windows.Forms.Form{privateSystem.Windows.Forms.Labellabel1;privateSystem.Windows.Forms.TextBoxtextBox1;privateSystem.Windows.Forms.Labellabel2;privateSystem.Windows.Forms.TextBoxtextBox2;privateSystem.Windows.Forms.Buttonbutton1;privateSystem.Windows.Forms.Buttonbutton2;///<summary>///必需的设计器变量。///</summary>privateSystem.ComponentModel.Containercomponents=null;publicForm1(){////Windows窗体设计器支持所必需的//InitializeComponent();////TODO:在InitializeComponent调用后添加任何构造函数代码//}///<summary>///清理所有正在使用的资源。///</summary>protectedoverridevoidDispose(booldisposing){if(disposing){if(components!=null){components.Dispose();}}base.Dispose(disposing);}#regionWindows窗体设计器生成的代码///<summary>///设计器支持所需的方法-不要使用代码编辑器修改///此方法的内容。///</summary>privatevoidInitializeComponent(){this.label1=newSystem.Windows.Forms.Label();this.textBox1=newSystem.Windows.Forms.TextBox();this.label2=newSystem.Windows.Forms.Label();this.textBox2=newSystem.Windows.Forms.TextBox();this.button1=newSystem.Windows.Forms.Button();this.button2=newSystem.Windows.Forms.Button();this.SuspendLayout();////label1//this.label1.Location=newSystem.Drawing.Point(32,32);this.label1.Name="label1";this.label1.Size=newSystem.Drawing.Size(56,16);this.label1.TabIndex=0;this.label1.Text="主机名:";////textBox1//this.textBox1.Location=newSystem.Drawing.Point(96,24);this.textBox1.Name="textBox1";this.textBox1.Size=newSystem.Drawing.Size(192,21);this.textBox1.TabIndex=1;this.textBox1.Text="";////label2//this.label2.Location=newSystem.Drawing.Point(32,64);this.label2.N