社区
VC.NET
帖子详情
获取本地计算机的IP和名称
ledon1981
2004-04-08 11:34:03
如何获取本地计算机的IP和计算机名呢?
请指导一下~
...全文
107
1
打赏
收藏
获取本地计算机的IP和名称
如何获取本地计算机的IP和计算机名呢? 请指导一下~
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
1 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
hychieftain
2004-04-08
打赏
举报
回复
//导入程序用到的名称空间
using System ;
using System.Net;
using System.Windows.Forms ;
using System.Drawing ;
public class Form3 : Form
{
//定义二个标签
private Label label1 ;
private Label label2 ;
public static void Main ( )
{
Application.Run ( new Form3 ( ) ) ;
}
// 构造窗体
public Form3 ( )
{
// 建立标签并且初始化
this.label1 = new System.Windows.Forms.Label ( ) ;
this.label2 = new System.Windows.Forms.Label ( ) ;
//先继承一个Label 类
label1.Location = new System.Drawing.Point ( 24 , 16 ) ;
label2.Location = new System.Drawing.Point ( 44 , 36 ) ;
//设定 Label的显示位置
label1.Text = "主机名称:" + System.Net.Dns.GetHostName ( ) ;
// 显示本机的计算机名称
label2.Text = "IP 地址:" + getIPAddress ( ) ;
// 显示本机的局域网IP地址
label1.Size = new System.Drawing.Size ( 200 , 50 ) ;
label2.Size = new System.Drawing.Size ( 200 , 80 ) ;
//设定标签的大小
label1.TabIndex = 0 ;
label2.TabIndex = 1 ;
label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter ;
label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter ;
// 设定标签的对齐方式
this.Text = "获得主机名称和IP地址!" ;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent ;
this.AutoScaleBaseSize = new System.Drawing.Size ( 8 , 16 ) ;
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D ;
// 设定窗体的边界类型
this.ForeColor = System.Drawing.SystemColors.Desktop ;
this.Font = new System.Drawing.Font ( "宋体" , 10 , System.Drawing.FontStyle.Bold ) ;
// 设定字体、大小就字体的式样
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide ;
this.ClientSize = new System.Drawing.Size ( 250 , 250 ) ;
//把标签加到窗体中
this.Controls.Add ( this.label1 ) ;
this.Controls.Add ( this.label2 ) ;
}
private static string getIPAddress ( )
{
System.Net.IPAddress addr;
// 获得本机局域网IP地址
addr = new System.Net.IPAddress ( Dns.GetHostByName ( Dns.GetHostName ( ) ) .AddressList [0].Address ) ;
return addr.ToString ( ) ;
}
}
安装和配置 Windows Server 2022 DNS 服务
DNS
名称
解析服务,本质上就是一个
IP
地址与
计算机
名称
对应的数据库,它允许网络当中的
计算机
自动注册自己的
名称
和
IP
地址信息到数据库当中,或者管理员也可以手动地在数据库当中添加记录,同样,网络当中的
计算机
...
获取
本地
计算机
的
名称
和
IP
地址
本程序介绍如何
获取
本地
计算机
的
名称
和
IP
地址。 向窗体上添加两个TLabel组件、两个TEdit组件和一个TButton组件,设计完成的主界面如图6-8所示。 图6-8 主界面 首先在程序的uses段中添加对WinSock的引用,...
java根据
ip
获取
计算机
名称
_Java如何
获取
本地
计算机
的
IP
地址和主机名?
在Java编程中,如何
获取
本地
计算机
的
IP
地址和主机名?以下示例显示如何使用InetAddress类的getLocalAddress()方法
获取
系统的本地
IP
地址和主机名。package com.yiibai;import java.net.InetAddress;public class Get...
使用InetAddress类
获取
本地
计算机
的
IP
地址和主机名
20、使用InetAddress类
获取
本地
计算机
的
IP
地址和主机名,甲骨文公司(www.oracle.com)主机的
IP
地址。 1)通过InetAddress.getLocalHost();
获取
本地
计算机
的InetAddress对象 2)通过InetAddress.getByName(...
vue 项目
获取
本地
IP
+用户
名称
vue 项目
获取
本地
IP
+用户
名称
VC.NET
7,540
社区成员
27,673
社区内容
发帖
与我相关
我的任务
VC.NET
.NET技术 VC.NET
复制链接
扫一扫
分享
社区描述
.NET技术 VC.NET
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章