Главная страница
    Top.Mail.Ru    Яндекс.Метрика
Форум: "Сети";
Текущий архив: 2004.02.17;
Скачать: [xml.tar.bz2];

Вниз

Как получить все IP-адреса, связанные с хостом?   Найти похожие ветки 

 
BPK   (2003-12-13 23:43) [0]

Есть компьютер с двумя сетевыми картами.
Пробую получить его IP-адреса с помощью GetHostByName, но получается только один.
Вернее, может быть, функция выдаёт несколько адресов, но я
знаю только как получить первый из них.

Помогите разобраться со структурой, возвращаемой функцией GetHostByName:
hostent = record
h_name: PChar;
h_aliases: ^PChar;
h_addrtype: Smallint;
h_length: Smallint;
case Byte of
0: (h_addr_list: ^PChar);
1: (h_addr: ^PChar)
end;

А конкретно - судя по описанию, h_aliases и h_addr_list это
указатели на массивы указателей PChar.
Как узнать, сколько указателей в массиве (т.е. сколько IP-адресов и синонимов у хоста)?


 
Verg   (2003-12-15 11:45) [1]

GetIpAddrTable
The GetIpAddrTable function retrieves the interface–to–IP address mapping table.

DWORD GetIpAddrTable(
PMIB_IPADDRTABLE pIpAddrTable, // buffer for mapping table
PULONG pdwSize, // size of buffer
BOOL bOrder // sort the table
);
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, use FormatMessage to obtain the message string for the returned error.

Requirements
Windows NT/2000/XP: Included in Windows NT 4.0 SP4; Windows 2000; Windows XP Pro; and Windows .NET Server.
Windows 95/98/Me: Included in Windows 98 and later.
Header: Declared in Iphlpapi.h.
Library: Use Iphlpapi.lib.


 
Sha   (2003-12-15 18:49) [2]

Author: Franчois PIETTE

var
IPList : TStrings;
procedure GetIPList(phe : PHostEnt; ToList : TStrings);
type
TaPInAddr = array [0..255] of PInAddr;
PaPInAddr = ^TaPInAddr;
var
pptr : PaPInAddr;
I : Integer;
begin
pptr := PaPInAddr(Phe^.h_addr_list);

I := 0;
while pptr^[I] <> nil do begin
ToList.Add(StrPas(WSocket_inet_ntoa(pptr^[I]^)));
Inc(I);
end;
end;

function LocalIPList : TStrings;
var
phe : PHostEnt;
begin
IPList.Clear;
Result := IPList;

phe := WSocketGetHostByName(LocalHostName);
if phe <> nil then
GetIpList(Phe, IPList);
end;


 
Sha   (2003-12-15 18:50) [3]

initialization
IPList := TStringList.Create;

finalization
if Assigned(IPList) then begin
IPList.Destroy;
IPList := nil;
end;



Страницы: 1 вся ветка

Форум: "Сети";
Текущий архив: 2004.02.17;
Скачать: [xml.tar.bz2];

Наверх





Память: 0.45 MB
Время: 0.009 c
14-53699
Gero
2004-01-29 23:16
2004.02.17
Цвета в интерфейсе Office XP


14-53729
_none_
2004-01-29 00:03
2004.02.17
зачем мтс ввели цензуру в смс-ках?


7-53789
~DR~
2003-12-01 11:38
2004.02.17
создание виртуального устройства


14-53767
zetovich
2004-01-30 12:55
2004.02.17
Как в ХР Проф на зашареный ресурс поставить пароль??


14-53741
Серый
2004-01-27 10:31
2004.02.17
Что из виндовых библиотек нужно по минимуму для работы визуально





Afrikaans Albanian Arabic Armenian Azerbaijani Basque Belarusian Bulgarian Catalan Chinese (Simplified) Chinese (Traditional) Croatian Czech Danish Dutch English Estonian Filipino Finnish French
Galician Georgian German Greek Haitian Creole Hebrew Hindi Hungarian Icelandic Indonesian Irish Italian Japanese Korean Latvian Lithuanian Macedonian Malay Maltese Norwegian
Persian Polish Portuguese Romanian Russian Serbian Slovak Slovenian Spanish Swahili Swedish Thai Turkish Ukrainian Urdu Vietnamese Welsh Yiddish Bengali Bosnian
Cebuano Esperanto Gujarati Hausa Hmong Igbo Javanese Kannada Khmer Lao Latin Maori Marathi Mongolian Nepali Punjabi Somali Tamil Telugu Yoruba
Zulu
Английский Французский Немецкий Итальянский Португальский Русский Испанский