zoukankan      html  css  js  c++  java
  • 获取本机IP

    uses Winapi.WinSock;

    function GetLocalIpList(IPList: TStrings): Integer;
    type
    TaPInAddr = array [0 .. 10] of PInAddr;
    PaPInAddr = ^TaPInAddr;
    var
    HostName : array [0 .. MAX_PATH] of AnsiChar;
    NameLen : Integer;
    WSData : TWSAData;
    lpHostEnt: PHostEnt;
    I : Integer;
    pptr : PaPInAddr;
    begin
    Result := 0;
    if WSAStartup(MakeWord(2, 0), WSData) <> 0 then
    Exit;
    try
    NameLen := SizeOf(HostName);
    FillChar(HostName, NameLen, 0);
    NameLen := GetHostName(HostName, NameLen);
    if NameLen = SOCKET_ERROR then
    Exit;
    lpHostEnt := GetHostByName(HostName);
    if lpHostEnt = nil then
    Exit;
    I := 0;
    pptr := PaPInAddr(lpHostEnt^.h_addr_list);
    IPList.Clear;
    while pptr^[I] <> nil do
    begin
    IPList.Add(string(AnsiString(inet_ntoa(pptr^[I]^))));
    Inc(I);
    end;
    Result := IPList.count;
    finally
    WSACleanup;
    end;
    end;

  • 相关阅读:
    Markdown
    异异还原
    程序和算法
    运算符
    Java复习1
    复习总结
    为什么Byte是8位,但是却只能表示到127,而不是255?
    笔记的认识
    笔记本触摸板
    电脑热键
  • 原文地址:https://www.cnblogs.com/maweiwei/p/11898223.html
Copyright © 2011-2022 走看看