interface
uses
SysUtils
,Windows
,dialogs
,winsock
,Classes
,ComObj
,WinInet;
//得到本機(jī)的局域網(wǎng)Ip地址
Function GetLocalIp(var LocalIp:string): Boolean;
//通過Ip返回機(jī)器名
Function GetNameByIPAddr(IPAddr: string; var MacName: string): Boolean ;
//獲取網(wǎng)絡(luò)中SQLServer列表
Function GetSQLServerList(var List: Tstringlist): Boolean;
//獲取網(wǎng)絡(luò)中的所有網(wǎng)絡(luò)類型
Function GetNetList(var List: Tstringlist): Boolean;
//獲取網(wǎng)絡(luò)中的工作組
Function GetGroupList(var List: TStringList): Boolean;
//獲取工作組中所有計(jì)算機(jī)
Function GetUsers(GroupName: string; var List: TStringList): Boolean;
//獲取網(wǎng)絡(luò)中的資源
Function GetUserResource(IpAddr: string; var List: TStringList): Boolean;
//映射網(wǎng)絡(luò)驅(qū)動(dòng)器
Function NetAddConnection(NetPath: Pchar; PassWord: Pchar;LocalPath: Pchar): Boolean;
//檢測網(wǎng)絡(luò)狀態(tài)
Function CheckNet(IpAddr:string): Boolean;
//檢測機(jī)器是否登入網(wǎng)絡(luò)
Function CheckMacAttachNet: Boolean;
//判斷Ip協(xié)議有沒有安裝 這個(gè)函數(shù)有問題
Function IsIPInstalled : boolean;
//檢測機(jī)器是否上網(wǎng)
Function InternetConnected: Boolean;
implementation
{=================================================================
功 能: 檢測機(jī)器是否登入網(wǎng)絡(luò)
參 數(shù): 無
返回值: 成功: 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;
{=================================================================
功 能: 返回本機(jī)的局域網(wǎng)Ip地址
參 數(shù): 無
返回值: 成功: 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返回機(jī)器名
參 數(shù):
IpAddr: 想要得到名字的Ip
返回值: 成功: 機(jī)器名 失敗: ‘‘
備 注:
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;
{=================================================================
功 能: 返回網(wǎng)絡(luò)中SQLServer列表
參 數(shù):
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協(xié)議有沒有安裝
參 數(shù): 無
返回值: 成功: True 失敗: False;
備 注: 該函數(shù)還有問題
版 本:
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;
聯(lián)系客服