怎样获取局域网客户机的IP地址及主机名等相关网络配置信息?(50分)

  • 主题发起人 主题发起人 HY_IHFGHY_HY
  • 开始时间 开始时间
H

HY_IHFGHY_HY

Unregistered / Unconfirmed
GUEST, unregistred user!
各位高手,请问怎样用DelPhi程序获取局域网客户机本机的网络配置,即:
   主机名、工作组名、计算机说明、IP地址、子网掩码、网关、
   WINS、DNS、本机网卡的MAC地址,
我想以字符串的形式将以上各项网络配置保存成一个文本。
请问有这样的API函数可以直接调用吗?
我想写一个通用的,就是在Windows95/98/Me/NT/2000/Xp都可以获取,谢谢各位了!
 
请问版主,这个贴子已有两个星期了,没人理我,能否删除此贴,并将分数送还给我?
谢谢!
 
http://zhuwei.5235.cn/
处有你想要的代码。是大富翁zw84611的个人主页。他来的话,分给他吧。
 
类似的,不知道有没有帮助
function GetUsers(GroupName: string; var List: TStringList): Boolean;
type
TNetResourceArray = ^TNetResource; //ÍøÂçÀàÐ͵ÄÊý×é
var
NetResource: TNetResource;
Buf: Pointer;
Count, BufSize, Res: DWord;
Ind: Integer;
lphEnum: THandle;
Temp: TNetResourceArray;
begin
Result := False;
FillChar(NetResource, SizeOf(NetResource), 0); //³õʼ»¯ÍøÂç²ã´ÎÐÅÏ¢
NetResource.lpRemoteName := @GroupName[1]; //Ö¸¶¨¹¤×÷×éÃû³Æ
NetResource.dwDisplayType := RESOURCEDISPLAYTYPE_SERVER; //ÀàÐÍΪ·þÎñÆ÷£¨¹¤×÷×飩
NetResource.dwUsage := RESOURCEUSAGE_CONTAINER;
NetResource.dwScope := RESOURCETYPE_DISK; //ÁоÙÎļþ×ÊÔ´ÐÅÏ¢
//»ñÈ¡Ö¸¶¨¹¤×÷×éµÄÍøÂç×ÊÔ´¾ä±ú
Res := WNetOpenEnum(RESOURCE_GLOBALNET, RESOURCETYPE_DISK,
RESOURCEUSAGE_CONTAINER, @NetResource, lphEnum);
if Res <> NO_ERROR then Exit; //&amp;Ouml;&amp;acute;&amp;ETH;&amp;ETH;&amp;Ecirc;§°&amp;Uuml;
while True do //&amp;Aacute;&amp;ETH;&amp;frac34;&amp;Ugrave;&amp;Ouml;&amp;cedil;&amp;para;¨&amp;sup1;¤×÷×é&amp;micro;&amp;Auml;&amp;Iacute;&amp;oslash;&amp;Acirc;&amp;ccedil;×&amp;Ecirc;&amp;Ocirc;&amp;acute;
begin
Count := $FFFFFFFF; //&amp;sup2;&amp;raquo;&amp;Iuml;&amp;THORN;×&amp;Ecirc;&amp;Ocirc;&amp;acute;&amp;Ecirc;&amp;yacute;&amp;Auml;&amp;iquest;
BufSize := 8192; //&amp;raquo;&amp;ordm;&amp;sup3;&amp;aring;&amp;Ccedil;&amp;oslash;&amp;acute;ó&amp;ETH;&amp;iexcl;&amp;Eacute;è&amp;Ouml;&amp;Atilde;&amp;Icirc;&amp;ordf;8K
GetMem(Buf, BufSize); //&amp;Eacute;ê&amp;Ccedil;&amp;euml;&amp;Auml;&amp;Uacute;&amp;acute;&amp;aelig;&amp;pound;&amp;not;&amp;Oacute;&amp;Atilde;&amp;Oacute;&amp;Uacute;&amp;raquo;&amp;ntilde;&amp;Egrave;&amp;iexcl;&amp;sup1;¤×÷×é&amp;ETH;&amp;Aring;&amp;Iuml;&amp;cent;
//&amp;raquo;&amp;ntilde;&amp;Egrave;&amp;iexcl;&amp;frac14;&amp;AElig;&amp;Euml;&amp;atilde;&amp;raquo;ú&amp;Atilde;&amp;ucirc;&amp;sup3;&amp;AElig;
Res := WNetEnumResource(lphEnum, Count, Pointer(Buf), BufSize);
if Res = ERROR_NO_MORE_ITEMS then break; //×&amp;Ecirc;&amp;Ocirc;&amp;acute;&amp;Aacute;&amp;ETH;&amp;frac34;&amp;Ugrave;&amp;Iacute;ê±&amp;Iuml;
if (Res <> NO_ERROR) then Exit; //&amp;Ouml;&amp;acute;&amp;ETH;&amp;ETH;&amp;Ecirc;§°&amp;Uuml;
Temp := TNetResourceArray(Buf);
for Ind := 0 to Count - 1 do //&amp;Aacute;&amp;ETH;&amp;frac34;&amp;Ugrave;&amp;sup1;¤×÷×é&amp;micro;&amp;Auml;&amp;frac14;&amp;AElig;&amp;Euml;&amp;atilde;&amp;raquo;ú&amp;Atilde;&amp;ucirc;&amp;sup3;&amp;AElig;
begin
//&amp;raquo;&amp;ntilde;&amp;Egrave;&amp;iexcl;&amp;sup1;¤×÷×é&amp;micro;&amp;Auml;&amp;frac14;&amp;AElig;&amp;Euml;&amp;atilde;&amp;raquo;ú&amp;Atilde;&amp;ucirc;&amp;sup3;&amp;AElig;&amp;pound;&amp;not;+2±í&amp;Ecirc;&amp;frac34;&amp;Eacute;&amp;frac34;&amp;sup3;&amp;yacute;"//"&amp;pound;&amp;not;&amp;Egrave;&amp;ccedil;//wangfajun=>wangfajun
List.Add(Temp^.lpRemoteName + 2);
Inc(Temp);
end;
end;
Res := WNetCloseEnum(lphEnum); //&amp;sup1;&amp;Oslash;±&amp;Otilde;&amp;Ograve;&amp;raquo;&amp;acute;&amp;Icirc;&amp;Aacute;&amp;ETH;&amp;frac34;&amp;Ugrave;
if Res <> NO_ERROR then exit; //&amp;Ouml;&amp;acute;&amp;ETH;&amp;ETH;&amp;Ecirc;§°&amp;Uuml;
Result := True;
FreeMem(Buf);
end;

function GetServerList(var List: TStringList): Boolean;
type
TNetResourceArray = ^TNetResource; //&amp;Iacute;&amp;oslash;&amp;Acirc;&amp;ccedil;&amp;Agrave;à&amp;ETH;&amp;Iacute;&amp;micro;&amp;Auml;&amp;Ecirc;&amp;yacute;×é
var
NetResource: TNetResource;
Buf: Pointer;
Count, BufSize, Res: DWORD;
lphEnum: THandle;
p: TNetResourceArray;
i, j: SmallInt;
NetworkTypeList: TList;
begin
Result := False;
NetworkTypeList := TList.Create;
List.Clear;
//&amp;raquo;&amp;ntilde;&amp;Egrave;&amp;iexcl;&amp;Otilde;&amp;ucirc;&amp;cedil;&amp;ouml;&amp;Iacute;&amp;oslash;&amp;Acirc;&amp;ccedil;&amp;Ouml;&amp;ETH;&amp;micro;&amp;Auml;&amp;Icirc;&amp;Auml;&amp;frac14;&amp;thorn;×&amp;Ecirc;&amp;Ocirc;&amp;acute;&amp;micro;&amp;Auml;&amp;frac34;&amp;auml;±ú&amp;pound;&amp;not;lphEnum&amp;Icirc;&amp;ordf;·&amp;micro;&amp;raquo;&amp;Oslash;&amp;Atilde;&amp;ucirc;±ú
Res := WNetOpenEnum(RESOURCE_GLOBALNET, RESOURCETYPE_DISK,
RESOURCEUSAGE_CONTAINER, nil, lphEnum);
if Res <> NO_ERROR then exit; //Raise Exception(Res);//&amp;Ouml;&amp;acute;&amp;ETH;&amp;ETH;&amp;Ecirc;§°&amp;Uuml;
//&amp;raquo;&amp;ntilde;&amp;Egrave;&amp;iexcl;&amp;Otilde;&amp;ucirc;&amp;cedil;&amp;ouml;&amp;Iacute;&amp;oslash;&amp;Acirc;&amp;ccedil;&amp;Ouml;&amp;ETH;&amp;micro;&amp;Auml;&amp;Iacute;&amp;oslash;&amp;Acirc;&amp;ccedil;&amp;Agrave;à&amp;ETH;&amp;Iacute;&amp;ETH;&amp;Aring;&amp;Iuml;&amp;cent;
Count := $FFFFFFFF; //&amp;sup2;&amp;raquo;&amp;Iuml;&amp;THORN;×&amp;Ecirc;&amp;Ocirc;&amp;acute;&amp;Ecirc;&amp;yacute;&amp;Auml;&amp;iquest;
BufSize := 8192; //&amp;raquo;&amp;ordm;&amp;sup3;&amp;aring;&amp;Ccedil;&amp;oslash;&amp;acute;ó&amp;ETH;&amp;iexcl;&amp;Eacute;è&amp;Ouml;&amp;Atilde;&amp;Icirc;&amp;ordf;8K
GetMem(Buf, BufSize); //&amp;Eacute;ê&amp;Ccedil;&amp;euml;&amp;Auml;&amp;Uacute;&amp;acute;&amp;aelig;&amp;pound;&amp;not;&amp;Oacute;&amp;Atilde;&amp;Oacute;&amp;Uacute;&amp;raquo;&amp;ntilde;&amp;Egrave;&amp;iexcl;&amp;sup1;¤×÷×é&amp;ETH;&amp;Aring;&amp;Iuml;&amp;cent;
Res := WNetEnumResource(lphEnum, Count, Pointer(Buf), BufSize);
if (Res = ERROR_NO_MORE_ITEMS) //×&amp;Ecirc;&amp;Ocirc;&amp;acute;&amp;Aacute;&amp;ETH;&amp;frac34;&amp;Ugrave;&amp;Iacute;ê±&amp;Iuml;
or (Res <> NO_ERROR) //&amp;Ouml;&amp;acute;&amp;ETH;&amp;ETH;&amp;Ecirc;§°&amp;Uuml;
then Exit;
P := TNetResourceArray(Buf);
for I := 0 to Count - 1 do //&amp;frac14;&amp;Ccedil;&amp;Acirc;&amp;frac14;&amp;cedil;÷&amp;cedil;&amp;ouml;&amp;Iacute;&amp;oslash;&amp;Acirc;&amp;ccedil;&amp;Agrave;à&amp;ETH;&amp;Iacute;&amp;micro;&amp;Auml;&amp;ETH;&amp;Aring;&amp;Iuml;&amp;cent;
begin
NetworkTypeList.Add(p);
Inc(P);
end;
//WNetCloseEnum&amp;sup1;&amp;Oslash;±&amp;Otilde;&amp;Ograve;&amp;raquo;&amp;cedil;&amp;ouml;&amp;Aacute;&amp;ETH;&amp;frac34;&amp;Ugrave;&amp;frac34;&amp;auml;±ú
Res := WNetCloseEnum(lphEnum); //&amp;sup1;&amp;Oslash;±&amp;Otilde;&amp;Ograve;&amp;raquo;&amp;acute;&amp;Icirc;&amp;Aacute;&amp;ETH;&amp;frac34;&amp;Ugrave;
if Res <> NO_ERROR then exit;
for J := 0 to NetworkTypeList.Count - 1 do //&amp;Aacute;&amp;ETH;&amp;sup3;&amp;ouml;&amp;cedil;÷&amp;cedil;&amp;ouml;&amp;Iacute;&amp;oslash;&amp;Acirc;&amp;ccedil;&amp;Agrave;à&amp;ETH;&amp;Iacute;&amp;Ouml;&amp;ETH;&amp;micro;&amp;Auml;&amp;Euml;ù&amp;Oacute;&amp;ETH;&amp;sup1;¤×÷×é&amp;Atilde;&amp;ucirc;&amp;sup3;&amp;AElig;
begin //&amp;Aacute;&amp;ETH;&amp;sup3;&amp;ouml;&amp;Ograve;&amp;raquo;&amp;cedil;&amp;ouml;&amp;Iacute;&amp;oslash;&amp;Acirc;&amp;ccedil;&amp;Agrave;à&amp;ETH;&amp;Iacute;&amp;Ouml;&amp;ETH;&amp;micro;&amp;Auml;&amp;Euml;ù&amp;Oacute;&amp;ETH;&amp;sup1;¤×÷×é&amp;Atilde;&amp;ucirc;&amp;sup3;&amp;AElig;
NetResource := TNetResource(NetworkTypeList.Items[J]^); //&amp;Iacute;&amp;oslash;&amp;Acirc;&amp;ccedil;&amp;Agrave;à&amp;ETH;&amp;Iacute;&amp;ETH;&amp;Aring;&amp;Iuml;&amp;cent;
//&amp;raquo;&amp;ntilde;&amp;Egrave;&amp;iexcl;&amp;Auml;&amp;sup3;&amp;cedil;&amp;ouml;&amp;Iacute;&amp;oslash;&amp;Acirc;&amp;ccedil;&amp;Agrave;à&amp;ETH;&amp;Iacute;&amp;micro;&amp;Auml;&amp;Icirc;&amp;Auml;&amp;frac14;&amp;thorn;×&amp;Ecirc;&amp;Ocirc;&amp;acute;&amp;micro;&amp;Auml;&amp;frac34;&amp;auml;±ú&amp;pound;&amp;not;NetResource&amp;Icirc;&amp;ordf;&amp;Iacute;&amp;oslash;&amp;Acirc;&amp;ccedil;&amp;Agrave;à&amp;ETH;&amp;Iacute;&amp;ETH;&amp;Aring;&amp;Iuml;&amp;cent;&amp;pound;&amp;not;lphEnum&amp;Icirc;&amp;ordf;·&amp;micro;&amp;raquo;&amp;Oslash;&amp;Atilde;&amp;ucirc;±ú
Res := WNetOpenEnum(RESOURCE_GLOBALNET, RESOURCETYPE_DISK,
RESOURCEUSAGE_CONTAINER, @NetResource, lphEnum);
if Res <> NO_ERROR then break; //&amp;Ouml;&amp;acute;&amp;ETH;&amp;ETH;&amp;Ecirc;§°&amp;Uuml;
while true do //&amp;Aacute;&amp;ETH;&amp;frac34;&amp;Ugrave;&amp;Ograve;&amp;raquo;&amp;cedil;&amp;ouml;&amp;Iacute;&amp;oslash;&amp;Acirc;&amp;ccedil;&amp;Agrave;à&amp;ETH;&amp;Iacute;&amp;micro;&amp;Auml;&amp;Euml;ù&amp;Oacute;&amp;ETH;&amp;sup1;¤×÷×é&amp;micro;&amp;Auml;&amp;ETH;&amp;Aring;&amp;Iuml;&amp;cent;
begin
Count := $FFFFFFFF; //&amp;sup2;&amp;raquo;&amp;Iuml;&amp;THORN;×&amp;Ecirc;&amp;Ocirc;&amp;acute;&amp;Ecirc;&amp;yacute;&amp;Auml;&amp;iquest;
BufSize := 8192; //&amp;raquo;&amp;ordm;&amp;sup3;&amp;aring;&amp;Ccedil;&amp;oslash;&amp;acute;ó&amp;ETH;&amp;iexcl;&amp;Eacute;è&amp;Ouml;&amp;Atilde;&amp;Icirc;&amp;ordf;8K
GetMem(Buf, BufSize); //&amp;Eacute;ê&amp;Ccedil;&amp;euml;&amp;Auml;&amp;Uacute;&amp;acute;&amp;aelig;&amp;pound;&amp;not;&amp;Oacute;&amp;Atilde;&amp;Oacute;&amp;Uacute;&amp;raquo;&amp;ntilde;&amp;Egrave;&amp;iexcl;&amp;sup1;¤×÷×é&amp;ETH;&amp;Aring;&amp;Iuml;&amp;cent;
//&amp;raquo;&amp;ntilde;&amp;Egrave;&amp;iexcl;&amp;Ograve;&amp;raquo;&amp;cedil;&amp;ouml;&amp;Iacute;&amp;oslash;&amp;Acirc;&amp;ccedil;&amp;Agrave;à&amp;ETH;&amp;Iacute;&amp;micro;&amp;Auml;&amp;Icirc;&amp;Auml;&amp;frac14;&amp;thorn;×&amp;Ecirc;&amp;Ocirc;&amp;acute;&amp;ETH;&amp;Aring;&amp;Iuml;&amp;cent;&amp;pound;&amp;not;
Res := WNetEnumResource(lphEnum, Count, Pointer(Buf), BufSize);
if (Res = ERROR_NO_MORE_ITEMS) //×&amp;Ecirc;&amp;Ocirc;&amp;acute;&amp;Aacute;&amp;ETH;&amp;frac34;&amp;Ugrave;&amp;Iacute;ê±&amp;Iuml;
or (Res <> NO_ERROR) //&amp;Ouml;&amp;acute;&amp;ETH;&amp;ETH;&amp;Ecirc;§°&amp;Uuml;
then break;
P := TNetResourceArray(Buf);
for I := 0 to Count - 1 do //&amp;Aacute;&amp;ETH;&amp;frac34;&amp;Ugrave;&amp;cedil;÷&amp;cedil;&amp;ouml;&amp;sup1;¤×÷×é&amp;micro;&amp;Auml;&amp;ETH;&amp;Aring;&amp;Iuml;&amp;cent;
begin
List.Add(StrPAS(P^.lpRemoteName));
Inc(P);
end;
end;
Res := WNetCloseEnum(lphEnum); //&amp;sup1;&amp;Oslash;±&amp;Otilde;&amp;Ograve;&amp;raquo;&amp;acute;&amp;Icirc;&amp;Aacute;&amp;ETH;&amp;frac34;&amp;Ugrave;
if Res <> NO_ERROR then break; //&amp;Ouml;&amp;acute;&amp;ETH;&amp;ETH;&amp;Ecirc;§°&amp;Uuml;
end;
Result := True;
FreeMem(Buf);
NetworkTypeList.Destroy;
end;
 
http://www.2ccc.com/article.asp?articleid=361
这里有源码,去看看,非常不错!
 
多人接受答案了。
 

Similar threads

D
回复
0
查看
1K
DelphiTeacher的专栏
D
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
后退
顶部