function LIP : string; type TaPInAddr = array [0..10] of PInAddr; PaPInAddr = ^TaPInAddr; var phe : PHostEnt; pptr : PaPInAddr; Buffer : array [0..63] of char; I : Integer; GInitData : TWSADATA; begin WSAStartup($101, GInitData); Result := ''; GetHostName(Buffer, SizeOf(Buffer)); phe :=GetHostByName(buffer); if phe = nil then Exit; pptr := PaPInAddr(Phe^.h_addr_list); I := 0; while pptr^[I] <> nil do begin result:=StrPas(inet_ntoa(pptr^[I]^)); Inc(I); end; WSACleanup; end;
IP助手函数里面能找到的。(mmsdn中ip helper函数族) 另外这些函数还包括网卡的一些设置。 增加一个IP地址。 很多呀 下面这个函数是得到一个数组的。 GetIpAddrTableThe GetIpAddrTable function retrieves the interface–to–IP address mapping table. DWORD GetIpAddrTable( PMIB_IPADDRTABLE pIpAddrTable, PULONG pdwSize, BOOL bOrder );Parameters pIpAddrTable [out] Pointer to a buffer that receives the interface–to–IP address mapping table as a MIB_IPADDRTABLE structure. pdwSize [in, out] On input, specifies the size of the buffer pointed to by the pIpAddrTable parameter. On output, if the buffer is not large enough to hold the returned mapping table, the function sets this parameter equal to the required buffer size.bOrder [in] Specifies whether the returned mapping table should be sorted in ascending order by IP address. If this parameter is TRUE, the table is sorted. Return Values If the function succeeds, the return value is NO_ERROR.If the function fails, the return value is one of the following error codes.Return Code Description ERROR_INSUFFICIENT_BUFFER The buffer pointed to by the pIpAddrTable parameter is not large enough. The required size is returned in the DWORD variable pointed to by the pdwSize parameter. ERROR_INVALID_PARAMETER The pdwSize parameter is NULL, or GetIpAddrTable is unable to write to the memory pointed to by the pdwSize parameter. ERROR_NOT_SUPPORTED This function is not supported on the operating system in use on the local system. Other Use FormatMessage to obtain the message string for the returned error.
failer(独败)你那个得到的是固定ip吧!
indy里面还有个函数 procedure TIdStackWindows.PopulateLocalAddresses; type TaPInAddr = Array[0..250] of PInAddr; PaPInAddr = ^TaPInAddr; var i: integer; AHost: PHostEnt; PAdrPtr: PaPInAddr; begin FLocalAddresses.Clear ; AHost := GetHostByName(PChar(WSGetHostName)); if AHost = nil then begin CheckForSocketError(SOCKET_ERROR); end else begin PAdrPtr := PAPInAddr(AHost^.h_address_list); i := 0; while PAdrPtr^[i] <> nil do begin FLocalAddresses.Add(TInAddrToString(PAdrPtr^[I]^)); Inc(I); end; end; end; 这是那个函数的原代码。是不是很简单,你可以直接调用就可以了。
2000中用ipconfig (好像是,记不太清)
delphi中编程如何实现!
type
TaPInAddr = array [0..10] of PInAddr;
PaPInAddr = ^TaPInAddr;
var
phe : PHostEnt;
pptr : PaPInAddr;
Buffer : array [0..63] of char;
I : Integer;
GInitData : TWSADATA;
begin
WSAStartup($101, GInitData);
Result := '';
GetHostName(Buffer, SizeOf(Buffer));
phe :=GetHostByName(buffer);
if phe = nil then Exit;
pptr := PaPInAddr(Phe^.h_addr_list);
I := 0;
while pptr^[I] <> nil do begin
result:=StrPas(inet_ntoa(pptr^[I]^));
Inc(I);
end;
WSACleanup;
end;
http://expert.csdn.net/Expert/TopicView1.asp?id=1937215
转的。
另外这些函数还包括网卡的一些设置。
增加一个IP地址。
很多呀
下面这个函数是得到一个数组的。
GetIpAddrTableThe GetIpAddrTable function retrieves the interface–to–IP address mapping table.
DWORD GetIpAddrTable(
PMIB_IPADDRTABLE pIpAddrTable,
PULONG pdwSize,
BOOL bOrder
);Parameters
pIpAddrTable
[out] Pointer to a buffer that receives the interface–to–IP address mapping table as a MIB_IPADDRTABLE structure.
pdwSize
[in, out] On input, specifies the size of the buffer pointed to by the pIpAddrTable parameter.
On output, if the buffer is not large enough to hold the returned mapping table, the function sets this parameter equal to the required buffer size.bOrder
[in] Specifies whether the returned mapping table should be sorted in ascending order by IP address. If this parameter is TRUE, the table is sorted.
Return Values
If the function succeeds, the return value is NO_ERROR.If the function fails, the return value is one of the following error codes.Return Code Description
ERROR_INSUFFICIENT_BUFFER The buffer pointed to by the pIpAddrTable parameter is not large enough. The required size is returned in the DWORD variable pointed to by the pdwSize parameter.
ERROR_INVALID_PARAMETER The pdwSize parameter is NULL, or GetIpAddrTable is unable to write to the memory pointed to by the pdwSize parameter.
ERROR_NOT_SUPPORTED This function is not supported on the operating system in use on the local system.
Other Use FormatMessage to obtain the message string for the returned error.
procedure TIdStackWindows.PopulateLocalAddresses;
type
TaPInAddr = Array[0..250] of PInAddr;
PaPInAddr = ^TaPInAddr;
var
i: integer;
AHost: PHostEnt;
PAdrPtr: PaPInAddr;
begin
FLocalAddresses.Clear ;
AHost := GetHostByName(PChar(WSGetHostName));
if AHost = nil then
begin
CheckForSocketError(SOCKET_ERROR);
end
else
begin
PAdrPtr := PAPInAddr(AHost^.h_address_list);
i := 0;
while PAdrPtr^[i] <> nil do
begin
FLocalAddresses.Add(TInAddrToString(PAdrPtr^[I]^));
Inc(I);
end;
end;
end;
这是那个函数的原代码。是不是很简单,你可以直接调用就可以了。