Pegar IP de duas placas de rede
Aí pessoal,
usei essa função para pegar o IP da minha placa de rede
Porem essa função só pega de uma placa de rede... Como faço pra pegar o IP de outras placas de rede que tiver no meu computador?
Abraço
usei essa função para pegar o IP da minha placa de rede
function PegaIP:string; //--> Declare a Winsock na clausula uses da unit var WSAData: TWSAData; HostEnt: PHostEnt; Name:string; begin WSAStartup(2, WSAData); SetLength(Name, 255); Gethostname(PChar(Name), 255); SetLength(Name, StrLen(PChar(Name))); HostEnt := gethostbyname(PChar(Name)); with HostEnt^ do begin Result := Format(´¬d.¬d.¬d.¬d´, [Byte(h_addr^[0]),Byte(h_addr^[1]), Byte(h_addr^[2]),Byte(h_addr^[3])]); end; WSACleanup; end;
Porem essa função só pega de uma placa de rede... Como faço pra pegar o IP de outras placas de rede que tiver no meu computador?
Abraço
Redoctober
Curtidas 0
Respostas
Otto
09/06/2004
Olá, eis o código:
agora, coloque um Memo e um combo no form, e um botão, no onclick do botão, vc faz:
flw... :wink:
const
ANY_SIZE = 1;
type
PTMibIPAddrRow = ^TMibIPAddrRow;
TMibIPAddrRow = packed record
dwAddr: DWORD;
dwIndex: DWORD;
dwMask: DWORD;
dwBCastAddr: DWORD;
dwReasmSize: DWORD;
Unused1,
Unused2: WORD;
end;
PTMibIPAddrTable = ^TMibIPAddrTable;
TMibIPAddrTable = packed record
dwNumEntries: DWORD;
Table: array[0..ANY_SIZE - 1] of TMibIPAddrRow;
end;
function GetIpAddrTable( pIpAddrTable: PTMibIPAddrTable;
pdwSize: PULONG;
bOrder: BOOL ): DWORD;
stdcall; external ´IPHLPAPI.DLL´;
{ converts IP-address in network byte order DWORD to dotted decimal string}
function IpAddr2Str( IPAddr: DWORD ): string;
var
i : integer;
begin
Result := ´´;
for i := 1 to 4 do
begin
Result := Result + Format( ´¬3d.´, [IPAddr and $FF] );
IPAddr := IPAddr shr 8;
end;
Delete( Result, Length( Result ), 1 );
end;
procedure Get_IPAddrTable(Tipo: Integer; List: TStrings );
var
IPAddrRow : TMibIPAddrRow;
TableSize : DWORD;
ErrorCode : DWORD;
i : integer;
pBuf : PChar;
NumEntries : DWORD;
begin
if not Assigned( List ) then EXIT;
List.Clear;
TableSize := 0; ;
// first call: get table length
ErrorCode := GetIpAddrTable( PTMibIPAddrTable( pBuf ), @TableSize, true );
if Errorcode <> ERROR_INSUFFICIENT_BUFFER then
EXIT;
GetMem( pBuf, TableSize );
// get table
ErrorCode := GetIpAddrTable( PTMibIPAddrTable( pBuf ), @TableSize, true );
if ErrorCode = NO_ERROR then
begin
NumEntries := PTMibIPAddrTable( pBuf )^.dwNumEntries;
if NumEntries > 0 then
begin
inc( pBuf, SizeOf( DWORD ) );
for i := 1 to NumEntries do
begin
Case Tipo of
1 : begin
IPAddrRow := PTMIBIPAddrRow( pBuf )^;
with IPAddrRow do
List.Add( Format( ´¬8.8x|¬15s|¬15s|¬15s|¬8.8d´,
[dwIndex, IPAddr2Str( dwAddr ), IPAddr2Str( dwMask ),
IPAddr2Str( dwBCastAddr ), dwReasmSize ] ) );
inc( pBuf, SizeOf( TMIBIPAddrRow ) );
end;
2 : begin
IPAddrRow := PTMIBIPAddrRow( pBuf )^;
List.Add( Format(´¬15s´,[IPAddr2Str(IPAddrRow.dwAddr)]) );
inc( pBuf, SizeOf( TMIBIPAddrRow ) );
end;
//3 : //;
end;
end;
end
else
List.Add( ´no entries.´ );
end
else
List.Add( SysErrorMessage( ErrorCode ) );
// we must restore pointer!
dec( pBuf, SizeOf( DWORD ) + NumEntries * SizeOf( IPAddrRow ) );
FreeMem( pBuf );
end;agora, coloque um Memo e um combo no form, e um botão, no onclick do botão, vc faz:
Get_IPAddrTable(1, Memo1.Lines); Get_IPAddrTable(2, ComboBox1.Items);
flw... :wink:
GOSTEI 0