interface
uses
SysUtils
,Windows
,dialogs
,winsock
,Classes
,ComObj
,WinInet;
//得到本機的局域網Ip地址
Function GetLocalIp(var LocalIp:string): Boolean;
//通過Ip返回機器名
Function GetNameByIPAddr(IPAddr: string; var MacName: string): Boolean ;
//獲取網絡中SQLServer列表
Function GetSQLServerList(var List: Tstringlist): Boolean;
//獲取網絡中的所有網絡類型
Function GetNetList(var List: Tstringlist): Boolean;
//獲取網絡中的工作組
Function GetGroupList(var List: TStringList): Boolean;
//獲取工作組中所有計算機
Function GetUsers(GroupName: string; var List: TStringList): Boolean;
//獲取網絡中的資源
Function GetUserResource(IpAddr: string; var List: TStringList): Boolean;
//映射網絡驅動器
Function NetAddConnection(NetPath: Pchar; PassWord: Pchar;LocalPath: Pchar): Boolean;
//檢測網絡狀態
Function CheckNet(IpAddr:string): Boolean;
//檢測機器是否登入網絡
Function CheckMacAttachNet: Boolean;
//判斷Ip協議有沒有安裝 這個函數有問題
Function IsIPInstalled : boolean;
//檢測機器是否上網
Function InternetConnected: Boolean;
implementation
{=================================================================
功 能: 檢測機器是否登入網絡
參 數: 無
返回值: 成功: True 失敗: False
備 注:
版 本:
1.0 2002/10/03 09:55:00
=================================================================}
Function CheckMacAttachNet: Boolean;
begin
Result := False;
if GetSystemMetrics(SM_NETWORK) <> 0 then
Result := True;
end;
{=================================================================
功 能: 返回本機的局域網Ip地址
參 數: 無
返回值: 成功: True, 並填充LocalIp 失敗: False
備 注:
版 本:
1.0 2002/10/02 21:05:00
=================================================================}
function GetLocalIP(var LocalIp: string): Boolean;
var
HostEnt: PHostEnt;
Ip: string;
addr: pchar;
Buffer: array [0..63] of char;
GInitData: TWSADATA;
begin
Result := False;
try
WSAStartup(2, GInitData);
GetHostName(Buffer, SizeOf(Buffer));
HostEnt := GetHostByName(buffer);
if HostEnt = nil then Exit;
addr := HostEnt^.h_addr_list^;
ip := Format('%d.%d.%d.%d', [byte(addr [0]),
byte (addr [1]), byte (addr [2]), byte (addr [3])]);
LocalIp := Ip;
Result := True;
finally
WSACleanup;
end;
end;
{=================================================================
功 能: 通過Ip返回機器名
參 數:
IpAddr: 想要得到名字的Ip
返回值: 成功: 機器名 失敗: ''
備 注:
inet_addr function converts a string containing an Internet
Protocol dotted address into an in_addr.
版 本:
1.0 2002/10/02 22:09:00
=================================================================}
function GetNameByIPAddr(IPAddr : String;var MacName:String): Boolean;
var
SockAddrIn: TSockAddrIn;
HostEnt: PHostEnt;
WSAData: TWSAData;
begin
Result := False;
if IpAddr = '' then exit;
try
WSAStartup(2, WSAData);
SockAddrIn.sin_addr.s_addr := inet_addr(PChar(IPAddr));
HostEnt := gethostbyaddr(@SockAddrIn.sin_addr.S_addr, 4, AF_INET);
if HostEnt <> nil then
MacName := StrPas(Hostent^.h_name);
Result := True;
finally
WSACleanup;
end;
end;
{=================================================================
功 能: 返回網絡中SQLServer列表
參 數:
List: 需要填充的List
返回值: 成功: True,並填充List 失敗 False
備 注:
版 本:
1.0 2002/10/02 22:44:00
=================================================================}
Function GetSQLServerList(var List: Tstringlist): boolean;
var
i: integer;
sRetValue: String;
SQLServer: Variant;
ServerList: Variant;
begin
Result := False;
List.Clear;
try
SQLServer := CreateOleObject('SQLDMO.Application');
ServerList := SQLServer.ListAvailableSQLServers;
for i := 1 to Serverlist.Count do
list.Add (Serverlist.item(i));
Result := True;
Finally
SQLServer := NULL;
ServerList := NULL;
end;
end;
{=================================================================
功 能: 判斷Ip協議有沒有安裝
參 數: 無
返回值: 成功: True 失敗: False;
備 注: 該函數還有問題
版 本:
1.0 2002/10/02 21:05:00
=================================================================}
Function IsIPInstalled : boolean;
var
WSData: TWSAData;
ProtoEnt: PProtoEnt;
begin
Result := True;
try
if WSAStartup(2,WSData) = 0 then
begin
ProtoEnt := GetProtoByName('IP');
if ProtoEnt = nil then
Result := False
end;
finally
WSACleanup;
end;
end;