Network function library

xiaoxiao2021-03-06  57

{================================================================================================================================================================================================================ ============ Features: Network Library Time: 2002/10/02 version: 1.0 备 Note: There is no matter to dry, copy writing and writing sorting some network functions for everyone. I hope everyone can continue to add =============================================== ==================} Unit Net;

Interface Uses Sysutils, Windows, Dialogs, Winsock, Classes, COMOBJ, WININET

// Get the local area network IP address Function GetLocalip (Var localip: string): boolean; // Return to machine name Function GetNameByipaddr (iPaddr: string; var MacName: String): boolean; // Get the network SQLServer list Function GetSqlServerList (VAR List: TStringList): boolean; // Get all network types in the network Function GetNetList (VAR List: tstringlist): boolean; // Gets the Working Group in the Network Function GetGroupList (Var List: Tstringlist): Boolean; / / Get all computers in the workgroup (Groupname: string; var list: tstringlist): boolean; // Get the resources in the network Function GetUserResource (iPaddr: string; var list: tstringlist): boolean; // Mapping network drive Function NetaddConnection (NetPath: PCHAR; PASSWORD: PCHAR; LOCALPATH: PCHAR): Boolean; // Detects Network Status Function Checknet (ipaddr: string): Boolean; // Detecting the machine login network Function CheckmacttachNet: Boolean;

/ / Decision IP protocol Do not install this function is issued in function isipinstalled: boolean; // Detects whether the machine is online Function InternetConnected: Boolean; Implementation

{================================================================================================================================================================================================================ ================ Fenergy: Detect the machine to log in to network parameters: no return value: success: true failed: false Note: Version: 1.0 2002/10/03 09:55 : 00 ==================================================== ==================} function checkmacttachnetic: boolean; begin result: = false; if getSystemmetrics (SM_NETWORK) <> 0 THEN Result: = true;

{================================================================================================================================================================================================================ ================ Features: Return to this machine's LAN IP address parameter: No return value: Success: True, and fill the localip failed: false Note: Version: 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: = 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;

{================================================================================================================================================================================================================ ================ Dump: IPAddr: IPADDR: IP Return value to get the name: Success: machine name failed: '' Note: inet_addr function Converts a string containing an internet protocol dotted address INTO AN IN_ADDR. Version: 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 dam. ;

{================================================================================================================================================================================================================ ================ Features: Return to the network SQLServer list parameters: list: List that needs to be filled Return: Success: True, and fill the list False Remarks: Version: 1.0 2002/10/02 22:44:00 ======================================== ================================================================================================================================ 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;

转载请注明原文地址:https://www.9cbs.com/read-109170.html

New Post(0)