Y
yeewa
Unregistered / Unconfirmed
GUEST, unregistred user!
IP地址的32位串是怎样写的呢?
通过下面这个程序可以获得本机IP,本人用的是Delphi6
如本机IP为192.168.1.59,
得到十六进制的IP串为3B01A8C0,翻译成十进制为59.1.168.192
请问这个32位的IP串是倒过来写的吗?
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus, StdCtrls, ExtCtrls, Winsock; //首先要添加winsock
type
TForm1 = class(TForm)
Timer1: TTimer;
Label1: TLabel;
PopupMenu1: TPopupMenu;
Exit: TMenuItem;
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure Label1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure Label1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure ExitClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
oldx,oldy: integer;//添加变量,用做移动窗体
oldIp: string;
implementation
{$R *.dfm}
//下面就是关键所在了
function LIP : string;
type
TaPInAddr = array [0..10] of PInAddr;
PaPInAddr = ^TaPInAddr;
var
phe : PHostEnt;
pptr : PaPInAddr;
Buffer : array [0..63] of char;
I : Integer;
GInitData : TWSADATA;
begin
WSAStartup($101, GInitData);
Result := '';
GetHostName(Buffer, SizeOf(Buffer));
phe :=GetHostByName(buffer);
if phe = nil then Exit;
pptr := PaPInAddr(Phe^.h_addr_list);
I := 0;
while pptr^ <> nil do begin
result:=result+#10+#13+'本机IP地址:'+StrPas(inet_ntoa(pptr^^));
result:=result+#10+#13+'本机32位IP串:'+inttohex(pptr^^.S_addr,2);
Inc(I);
end;
WSACleanup;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
with Label1 do //定义属性
begin
Caption:='';
Font.Charset:=ANSI_CHARSET;
Font.Name:='Arial';
Font.Size:=10;
Font.Color:=clRed;
Align:=alClient;
PopupMenu:=popupmenu1;
end;
Timer1.Interval:=1000;
Timer1.Enabled:=true;
Label1.Caption:='IP:'+LIP; //赋值,把ip赋值给label1
oldIp:=LIP;
BorderStyle:=bsNone;
Alphablend:=true; //呵呵,这个就是让窗口变的透明的办法了
Alphablendvalue:=200;
FormStyle:=fsStayOnTop; //让窗体总在最前面
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
Label1.Caption :='IP:'+LIP;
if oldip <> LIP then
Showmessage('IP地址已经改变,请检查!');//提醒用户
end;
procedure TForm1.Label1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if ssleft in shift then //移动窗体form1
begin
Form1.Left:=Form1.Left+x-oldx;
Form1.Top:=Form1.top+y-oldy;
end;
end;
procedure TForm1.Label1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
oldx:=x;
oldy:=y;
end;
procedure TForm1.ExitClick(Sender: TObject);
begin
Close;
end;
end.
通过下面这个程序可以获得本机IP,本人用的是Delphi6
如本机IP为192.168.1.59,
得到十六进制的IP串为3B01A8C0,翻译成十进制为59.1.168.192
请问这个32位的IP串是倒过来写的吗?
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus, StdCtrls, ExtCtrls, Winsock; //首先要添加winsock
type
TForm1 = class(TForm)
Timer1: TTimer;
Label1: TLabel;
PopupMenu1: TPopupMenu;
Exit: TMenuItem;
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure Label1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure Label1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure ExitClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
oldx,oldy: integer;//添加变量,用做移动窗体
oldIp: string;
implementation
{$R *.dfm}
//下面就是关键所在了
function LIP : string;
type
TaPInAddr = array [0..10] of PInAddr;
PaPInAddr = ^TaPInAddr;
var
phe : PHostEnt;
pptr : PaPInAddr;
Buffer : array [0..63] of char;
I : Integer;
GInitData : TWSADATA;
begin
WSAStartup($101, GInitData);
Result := '';
GetHostName(Buffer, SizeOf(Buffer));
phe :=GetHostByName(buffer);
if phe = nil then Exit;
pptr := PaPInAddr(Phe^.h_addr_list);
I := 0;
while pptr^ <> nil do begin
result:=result+#10+#13+'本机IP地址:'+StrPas(inet_ntoa(pptr^^));
result:=result+#10+#13+'本机32位IP串:'+inttohex(pptr^^.S_addr,2);
Inc(I);
end;
WSACleanup;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
with Label1 do //定义属性
begin
Caption:='';
Font.Charset:=ANSI_CHARSET;
Font.Name:='Arial';
Font.Size:=10;
Font.Color:=clRed;
Align:=alClient;
PopupMenu:=popupmenu1;
end;
Timer1.Interval:=1000;
Timer1.Enabled:=true;
Label1.Caption:='IP:'+LIP; //赋值,把ip赋值给label1
oldIp:=LIP;
BorderStyle:=bsNone;
Alphablend:=true; //呵呵,这个就是让窗口变的透明的办法了
Alphablendvalue:=200;
FormStyle:=fsStayOnTop; //让窗体总在最前面
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
Label1.Caption :='IP:'+LIP;
if oldip <> LIP then
Showmessage('IP地址已经改变,请检查!');//提醒用户
end;
procedure TForm1.Label1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if ssleft in shift then //移动窗体form1
begin
Form1.Left:=Form1.Left+x-oldx;
Form1.Top:=Form1.top+y-oldy;
end;
end;
procedure TForm1.Label1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
oldx:=x;
oldy:=y;
end;
procedure TForm1.ExitClick(Sender: TObject);
begin
Close;
end;
end.