怖客-致力于对网络技术的研究!

delphi制作ip更新器实例代码 远控编写部分

自行添加内容

by:lxsky

怖客原创(http://www.bkhack.com

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Psock, NMFtp,winsock;  //记得要加WINSOCK库

type
  TForm1 = class(TForm)
    NMFTP1: TNMFTP;
    Edit1: TEdit;
    Button1: TButton;
    Edit2: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    Edit3: TEdit;
    Edit4: TEdit;
    Label3: TLabel;
    Label4: TLabel;
    Button2: TButton;
    Edit5: TEdit;
    Label5: TLabel;
    Edit6: TEdit;
    Edit7: TEdit;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    Memo1: TMemo;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure NMFTP1AuthenticationFailed(var Handled: Boolean);
    procedure NMFTP1Connect(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

//以下函数用以得本机IP地址。  
function  LocalIP: 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^[I] <> nil do begin
        result:=StrPas(inet_ntoa(pptr^[I]^));
        Inc(I);
     end;
     WSACleanup;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
   memo1.Visible:=false;//让MEMO控件不可见
   edit3.text:=localip; //调用函数得到本机外网IP地址
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
   nmftp1.Cancel;//断开连接

   if (edit6.Text='') or (edit7.text='') then //这里注意要用“=”(比较),不能用“:=”(赋值)
      begin
         showmessage('请输入FTP帐户和密码');
      end
   else
      begin
         nmftp1.Host:=edit1.Text; //服务器的IP地址
         nmftp1.Port:=strtoint(edit2.text);//端口是数字,这里要进行转换
         nmftp1.UserID:=edit6.text;  //FTP帐户
         nmftp1.Password:=edit7.Text;  //FTP密码
         nmftp1.Connect;  //发起连接
      end;
end;

procedure TForm1.NMFTP1AuthenticationFailed(var Handled: Boolean);
begin
   showmessage('连接失败!');
end;

procedure TForm1.NMFTP1Connect(Sender: TObject); //和FTP服务器连接成功
begin
   showmessage('连接并且更新成功!');
   memo1.Clear;//清空MEMO1的内容
   memo1.Text:=edit3.text+':'+edit4.text;
   memo1.Lines.SaveToFile('c:\temp.jpg');//把配置信息保存到本地
   nmftp1.Upload('c:\temp.jpg',edit5.text);//把本地文件上传到FTP服务器
   deletefile('c:\temp.jpg');//清除本地临时文件
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
   nmftp1.Disconnect;//断开连接
end;

end.
 

自行添加内容
标签:delphidelphi编程delphi网络编程delphi黑客编程
分类:编程教程| 发布:lxsky| 查看: | 发表时间:2011-12-26
原创文章如转载,请注明:转载自怖客,delphi教程,socket编程,vc 教程,电脑技术培训,网络安全 http://www.bkhack.com/
本文链接:http://www.bkhack.com/biancheng/delphiZhiZuoipGengXinQiShiLiDaiMa-YuanKongBianXieBuFen.html

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

自行添加内容