会员
众包
新闻
博问
闪存
赞助商
HarmonyOS
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
会员中心
简洁模式
...
退出登录
注册
登录
K3
博客园
::
首页
::
新随笔
::
联系
::
订阅
::
管理
公告
C# 如何得到局域网中的计算机名?
private
void
ScanTarget()
{
string
strIPAddress
=
"
192.168.1.
"
;
//
Start scan address
int
nStrat
=
Int32.Parse(
"
1
"
);
//
Finish scan address
int
nEnd
=
Int32.Parse(
"
255
"
);
//
scan operation
for
(
int
i
=
nStrat;i
<=
nEnd;i
++
)
{
string
strScanIPAdd
=
strIPAddress
+
i.ToString();
//
convert to ip address
IPAddress myScanIP
=
IPAddress.Parse(strScanIPAdd);
try
{
//
get dns information
IPHostEntry myScanHost
=
Dns.GetHostByAddress(myScanIP);
//
get host name
string
strHostName
=
myScanHost.HostName.ToString();
this
.listBox2.Items.Add(strScanIPAdd
+
"
->
"
+
strHostName
+
"
\r
"
);
}
catch
{
continue
;
}
}
//
for
MessageBox.Show(
"
ok
"
);
}
posted on
2005-04-29 15:11
K3
阅读(
953
) 评论(
0
)
收藏
举报
刷新页面
返回顶部
博客园
© 2004-2025
浙公网安备 33010602011771号
浙ICP备2021040463号-3