如何在启动机器时自动运行adsl拨号(1)[7]

[入库:2005年8月18日] [更新:2007年3月24日]

本文简介:选择自 zhujunfeng 的 blog

end;

procedure afterconnect;//等拨号完成后,访问指定页面,借此将ip地址记录下来,这样我们就可以在其他地方知道拨号后新的ip地址了
var
  hsocket: tsocket;
  saddr,sendtext:string;
  sendbuf:array[0..1024] of char;
  hostent:phostent;

begin
  try
    if not checkvisit then
    begin
      logmessage('----------'+getip+'----------');
      isconnected:=true;
      exit;
    end;

    hostent:=gethostbyname(pchar(visithost));
    if hostent<>nil then
    begin
     with hostent^ do
        saddr:=format('%d.%d.%d.%d',[byte(h_addr^[0]),byte(h_addr^[1]),byte(h_addr^[2]),byte(h_addr^[3])]);
    end;

    initsocket(hsocket,saddr,80,10000);
    sendtext:='post '+visiturl+' http/1.1'+#13#10
               +'accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*'+#13#10
               +'referer: '+#13#10
               +'accept-language: zh-cn'+#13#10
               +'content-type: application/x-www-form-urlencoded'+#13#10
               +'accept-encoding: gzip, deflate'+#13#10
               +'user-agent: mozilla/4.0 (compatible; msie 6.0; windows nt 5.1; .net clr 1.0.3705)'+#13#10
               +'host: '+visithost+#13#10
               +'content-length: '+inttostr(length(visitparam))+#13#10
               +'connection: keep-alive'+#13#10
               +'cache-control: no-cache'+#13#10
               +'cookie: '+#13#10
               +#13#10
               +visitparam+#13#10;
    fillchar(sendbuf,sizeof(sendbuf),0);
    strlcopy(sendbuf,pchar(sendtext),length(sendtext));
    send(hsocket,sendbuf,length(sendtext),0);

    uninitsocket(hsocket);

    logmessage('----------'+getip+'----------');
    isconnected:=true;
  except
  end;
end;

procedure disconnected;
begin
  try
    if hrasconn <> 0 then
    begin
      rashangupa(hrasconn);
      hrasconn:= 0;
    end;
  except
  end;
end;

procedure getactiveconn;
var
    dwret    : dword;
    ncb      : dword;
    buf      : array [0..255] of char;
begin
  try
    arasconn[0].dwsize := sizeof(arasconn[0]);
    ncb   := sizeof(arasconn);
    dwret := rasenumconnectionsa(@arasconn, @ncb, @nrasconncount);
    if dwret <> 0 then begin
        rasgeterrorstringa(dwret, @buf[0], sizeof(buf));
        logmessage(buf);
    end;
  except
  end;
end;

function getactiveconnhandle(szname : string) : thrasconn;
var
    i : integer;
begin
    getactiveconn;
    if nrasconncount > 0 then begin
        for i := 0 to nrasconncount - 1 do begin
            if stricomp(pchar(szname), arasconn[i].szentryname) = 0 then begin
                result := arasconn[i].hrasconn;
                exit;
            end;

本文关键:adsl 拨号 服务
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top