| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2444 人关注过本帖
标题:[求助]如何获取局域网的所有计算机
只看楼主 加入收藏
wyfandy
Rank: 1
来 自:深圳
等 级:新手上路
帖 子:376
专家分:0
注 册:2006-12-11
收藏
 问题点数:0 回复次数:21 
[求助]如何获取局域网的所有计算机
如何获取局域网的所有计算机和对应的IP地址,非常感谢最好能给个实例.

[此贴子已经被作者于2007-3-4 22:12:28编辑过]


搜索更多相关主题的帖子: 局域网 计算机 获取 
2007-03-03 22:02
king05
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2007-3-3
收藏
得分:0 
其实 这个还不如不写程序呢?
局域网一般都有网上邻居,你只要知道自己的ip和机号一般都能推算.

2007-03-04 00:18
wyfandy
Rank: 1
来 自:深圳
等 级:新手上路
帖 子:376
专家分:0
注 册:2006-12-11
收藏
得分:0 
我在用程序来枚举局域网的所有计算机呀!!!

谁能帮我呀!!!!

不论什么事,只要认准了一个目标,然后朝之不懈地努力,就一定实现。编程爱好者QQ群:21318556
2007-03-04 10:00
qhscqb
Rank: 1
等 级:新手上路
威 望:1
帖 子:343
专家分:0
注 册:2007-2-3
收藏
得分:0 

我想反正会用到API函数


编程快乐,快乐编程! 没有最好,只有更好!
2007-03-04 15:24
wyfandy
Rank: 1
来 自:深圳
等 级:新手上路
帖 子:376
专家分:0
注 册:2006-12-11
收藏
得分:0 

那位好心人帮帮我呀!!!!
我现在急要用程序来枚举局域网内的所有计算机和对应的IP地址.


不论什么事,只要认准了一个目标,然后朝之不懈地努力,就一定实现。编程爱好者QQ群:21318556
2007-03-05 14:16
清澂居士
Rank: 6Rank: 6
等 级:贵宾
威 望:28
帖 子:1237
专家分:7
注 册:2006-12-19
收藏
得分:0 
Net view
显示域列表、计算机列表或者由指定计算机共享的资源。

net view [\\computername | /domain[:domainname]]

net view /network:nw [\\computername]

参数



如果在没有参数的情况下使用,则 net view 显示当前域中的计算机列表。

\\computername

指定要查看其共享资源的计算机。

/domain[:domainname]

指定要查看其可用计算机的域。如果省略了 domainname,将显示网络中所有的域。

/network:nw

显示 NetWare 网络上所有可用的服务器。如果指定了计算机名,将显示 NetWare 网络中该计算机上的可用资源。添加到该系统的其他网络也可以使用该开关指定。

佛曰:\"前世的500次回眸才换来今生的一次擦肩而过\".我宁愿用来世的一次擦肩而过来换得今生的500次回眸.
2007-03-05 14:54
wyfandy
Rank: 1
来 自:深圳
等 级:新手上路
帖 子:376
专家分:0
注 册:2006-12-11
收藏
得分:0 

这个命令我知道,有没有不用这个命令的方法,或用API等直接在VB程序在枚举


不论什么事,只要认准了一个目标,然后朝之不懈地努力,就一定实现。编程爱好者QQ群:21318556
2007-03-05 15:10
清澂居士
Rank: 6Rank: 6
等 级:贵宾
威 望:28
帖 子:1237
专家分:7
注 册:2006-12-19
收藏
得分:0 

option explicit
private const resource_connected as long = &h1&
private const resource_globalnet as long = &h2&
private const resource_remembered as long = &h3&


private const resourcedisplaytype_directory& = &h9
private const resourcedisplaytype_domain& = &h1
private const resourcedisplaytype_file& = &h4
private const resourcedisplaytype_generic& = &h0
private const resourcedisplaytype_group& = &h5
private const resourcedisplaytype_network& = &h6
private const resourcedisplaytype_root& = &h7
private const resourcedisplaytype_server& = &h2
private const resourcedisplaytype_share& = &h3
private const resourcedisplaytype_shareadmin& = &h8
private const resourcetype_any as long = &h0&
private const resourcetype_disk as long = &h1&
private const resourcetype_print as long = &h2&
private const resourcetype_unknown as long = &hffff&
private const resourceusage_all as long = &h0&
private const resourceusage_connectable as long = &h1&
private const resourceusage_container as long = &h2&
private const resourceusage_reserved as long = &h80000000
private const no_error = 0
private const error_more_data = 234 'l // dderror
private const resource_enum_all as long = &hffff
private type netresource
dwscope as long
dwtype as long
dwdisplaytype as long
dwusage as long
plocalname as long
premotename as long
pcomment as long
pprovider as long
end type
private type netresource_real
dwscope as long
dwtype as long
dwdisplaytype as long
dwusage as long
slocalname as string
sremotename as string
scomment as string
sprovider as string
end type
private declare function wnetaddconnection2 lib "mpr.dll" alias "wnetaddconnection2a" (lpnetresource as netresource, byval lppassword as string, byval lpusername as string, byval dwflags as long) as long
private declare function wnetopenenum lib "mpr.dll" alias "wnetopenenuma" (byval dwscope as long, byval dwtype as long, byval dwusage as long, lpnetresource as any, lphenum as long) as long
private declare function wnetenumresource lib "mpr.dll" alias "wnetenumresourcea" (byval henum as long, lpccount as long, lpbuffer as netresource, lpbuffersize as long) as long
private declare function wnetcloseenum lib "mpr.dll" (byval henum as long) as long
private declare function varptrany lib "vb40032.dll" alias "varptr" (lpobject as any) as long
private declare sub copymem lib "kernel32" alias "rtlmovememory" (lpto as any, lpfrom as any, byval llen as long)
private declare sub copymembyptr lib "kernel32" alias "rtlmovememory" (byval lpto as long, byval lpfrom as long, byval llen as long)
private declare function lstrcpy lib "kernel32" alias "lstrcpya" (byval lpstring1 as string, byval lpstring2 as any) as long
private declare function lstrlen lib "kernel32" alias "lstrlena" (byval lpstring as any) as long
sub main()
const max_resources = 256
const not_a_container = -1


dim bfirsttime as boolean
dim lreturn as long
dim henum as long
dim lcount as long
dim lmin as long
dim llength as long
dim l as long
dim lbuffersize as long
dim llastindex as long
dim unetapi(0 to max_resources) as netresource
dim unet() as netresource_real
bfirsttime = true
do
if bfirsttime then
lreturn = wnetopenenum(resource_globalnet, resourcetype_any, resourceusage_all, byval 0&, henum)
bfirsttime = false
else
if unet(llastindex).dwusage and resourceusage_container then
lreturn = wnetopenenum(resource_globalnet, resourcetype_any, resourceusage_all, unet(llastindex), henum)
else
lreturn = not_a_container
henum = 0
end if
llastindex = llastindex + 1
end if
if lreturn = no_error then
lcount = resource_enum_all
do
lbuffersize = ubound(unetapi) * len(unetapi(0)) / 2
lreturn = wnetenumresource(henum, lcount, unetapi(0), lbuffersize)
if lcount > 0 then
redim preserve unet(0 to lmin + lcount - 1) as netresource_real
for l = 0 to lcount - 1
'each resource will appear here as unet(i)
unet(lmin + l).dwscope = unetapi(l).dwscope
unet(lmin + l).dwtype = unetapi(l).dwtype
unet(lmin + l).dwdisplaytype = unetapi(l).dwdisplaytype
unet(lmin + l).dwusage = unetapi(l).dwusage
if unetapi(l).plocalname then
llength = lstrlen(unetapi(l).plocalname)
unet(lmin + l).slocalname = space$(llength)
copymem byval unet(lmin + l).slocalname, byval unetapi(l).plocalname, llength
end if
if unetapi(l).premotename then
llength = lstrlen(unetapi(l).premotename)
unet(lmin + l).sremotename = space$(llength)
copymem byval unet(lmin + l).sremotename, byval unetapi(l).premotename, llength
end if
if unetapi(l).pcomment then
llength = lstrlen(unetapi(l).pcomment)
unet(lmin + l).scomment = space$(llength)
copymem byval unet(lmin + l).scomment, byval unetapi(l).pcomment, llength
end if
if unetapi(l).pprovider then
llength = lstrlen(unetapi(l).pprovider)
unet(lmin + l).sprovider = space$(llength)
copymem byval unet(lmin + l).sprovider, byval unetapi(l).pprovider, llength
end if
next l
end if
lmin = lmin + lcount
loop while lreturn = error_more_data
end if
if henum then
l = wnetcloseenum(henum)
end if
loop while llastindex < lmin
if ubound(unet) > 0 then
for l = 0 to ubound(unet)
select case unet(l).dwdisplaytype
case resourcedisplaytype_directory&
debug.print "directory...",
case resourcedisplaytype_domain
debug.print "domain...",
case resourcedisplaytype_file
debug.print "file...",
case resourcedisplaytype_generic
debug.print "generic...",
case resourcedisplaytype_group
debug.print "group...",
case resourcedisplaytype_network&
debug.print "network...",
case resourcedisplaytype_root&
debug.print "root...",
case resourcedisplaytype_server
debug.print "server...",
case resourcedisplaytype_share
debug.print "share...",
case resourcedisplaytype_shareadmin&
debug.print "shareadmin...",
end select
debug.print unet(l).sremotename, unet(l).scomment
next l
end if


佛曰:\"前世的500次回眸才换来今生的一次擦肩而过\".我宁愿用来世的一次擦肩而过来换得今生的500次回眸.
2007-03-05 15:37
wyfandy
Rank: 1
来 自:深圳
等 级:新手上路
帖 子:376
专家分:0
注 册:2006-12-11
收藏
得分:0 
版主非常感谢你热心的帮助,可是运行会出错!

lreturn = wnetopenenum(resource_globalnet, resourcetype_any, resourceusage_all, byval 0&, henum)

图片附件: 游客没有浏览图片的权限,请 登录注册


(我用的是XP SP2系统)

[此贴子已经被作者于2007-3-5 16:15:13编辑过]


不论什么事,只要认准了一个目标,然后朝之不懈地努力,就一定实现。编程爱好者QQ群:21318556
2007-03-05 16:14
wyfandy
Rank: 1
来 自:深圳
等 级:新手上路
帖 子:376
专家分:0
注 册:2006-12-11
收藏
得分:0 
这问题解决了,运行的结果是:
network... Microso
network... Microso
network... Web Cli
这个是网上邻居的整个目录下面的三个,这个不是我想要的结果呀!我是要整个局域网的计算机名称和IP,不是这三网络呀!

不论什么事,只要认准了一个目标,然后朝之不懈地努力,就一定实现。编程爱好者QQ群:21318556
2007-03-05 16:29
快速回复:[求助]如何获取局域网的所有计算机
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.025784 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved