各位!怎么把一个点分十进制的IP地址转成长整形?

解决方案 »

  1.   

    Uses Winsock;ShowMessage(IntToStr(inet_addr('132.241.5.10')));
      

  2.   

    function IPToLongInt(IP: String): LongWord;
    var
      vIndex: Integer;
      vIP: String;
    begin
      Result := 0;
      vIP := IP;
      vIndex := Pos('.', vIP);
      Result := Result + StrToInt(Copy(vIP, 1, vIndex - 1)) * $1000000;
      Delete(vIP, 1, vIndex);
      vIndex := Pos('.', vIP);
      Result := Result + StrToInt(Copy(vIP, 1, vIndex - 1)) * $10000;
      Delete(vIP, 1, vIndex);
      vIndex := Pos('.', vIP);
      Result := Result + StrToInt(Copy(vIP, 1, vIndex - 1)) * $100;
      Delete(vIP, 1, vIndex);
      Result := Result + StrToInt(vIP);
    end;function LongIntToIP(LnInt: LongWord): String;
    var
      vLnInt: LongWord;
    begin
      Result := IntToStr(LnInt div ($1000000)) + '.';
      vLnInt := LnInt mod $1000000;
      Result := Result + IntToStr(vLnInt div $10000) + '.';
      vLnInt := vLnInt mod $10000;
      Result := Result + IntToStr(vLnInt div $100) + '.' + IntToStr(vLnInt mod $100);
    end;