频道分类

Delphi IPNumberIPV4

作者:admin 来源: 日期:2021/1/23 22:57:12 人气: 标签:

 
unit Unit5;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs;

type
  TForm5 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form5: TForm5;

implementation

{$R *.dfm}


function GetIPNumberIPV4(ip: string): integer;
var
  List: TStringList;
  A, B, C, D, E, F: integer; //Biginteger...?
  total: string;
begin
  Result := 0;

  if ip = '::1' then
    ip := '127.0.0.1';

  List := TStringList.Create;
  try
    List.Delimiter := '.';
    List.StrictDelimiter := True;
    List.DelimitedText := ip;

    A := strtoint(List[0]);
    B := strtoint(List[1]);
    C := strtoint(List[2]);
    D := strtoint(List[3]);

 ////Result :=  (A shl 40) +  (B shl 32) + (C shl 24) + (D shl 16) + (E shl 8) + F; // BIG INTEGER PROBLEMS..

     Result := (A shl 24) + (B shl 16) + (C shl 8) + D;
  finally
    List.Free;
  end;
end;




procedure TForm5.FormCreate(Sender: TObject);
begin
text:=IntToStr(GetIPNumberIPV4('127.0.0.1'));
end;

end.

上一篇:Delphi 提取标签之间的字符串(重复标签)下一篇:没有资料