Помощь - Поиск - Пользователи - Календарь
Полная версия этой страницы: Дебаг Cgi
Форум программистов > Системное программирование > Delphi и Pascal > Delphi - Сети
vital
Набросал я тут CGI'шку одну..

При запуске в бродилке получаю ошибку 500. Message: '' invalid integer value.

Трабла в том что у меня преобразований int<=>str достаточно много и на первый взгляд все правильно.. Подскажите, пожалуйста, способ найти место где лажа на этих 159 строках..

Добавлено позже..решил вот код выложить..
index.html
<html>
<head>
<title>VIpScan</title>
</head>
<body>
<h1>Введите начальный IP:<br>
<form method=get action="project1.cgi"><nobr>
<input type=text name=fisrtip1p>.
<input type=text name=fisrtip2p>.
<input type=text name=fisrtip3p>.
<input type=text name=fisrtip4p></h1>
<h1>Введите конечный IP:<br>
<input type=text name=secip1p>.
<input type=text name=secip2p>.
<input type=text name=secip3p>.
<input type=text name=secip4p></h1></nobr>
<h1>Порт:</h1>
<input type=text name=port value=411>
<input type=submit value=Сканировать>
</form>
</body>
</html>

program Project1;
program Project1;

{$APPTYPE CONSOLE}
{$E cgi}
uses
  WebBroker,
  CGIApp,
  Unit1 in 'Unit1.pas' {WebModule1: TWebModule};

{$R *.res}

begin
  Application.Initialize;
  Application.CreateForm(TWebModule1, WebModule1);
  Application.Run;
end.

Unit1;
unit Unit1;

interface

uses
  SysUtils, Classes, HTTPApp, Sockets, ExtCtrls;

type
  TWebModule1 = class(TWebModule)
    TcpClient1: TTcpClient;
    Timer1: TTimer;
    procedure WebModuleCreate(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  WebModule1: TWebModule1;
  FirstIP1p,FirstIP2p,FirstIP3p,FirstIP4p:integer;
  SecIP1p,SecIP2p,SecIP3p,SecIP4p,Port:integer;
implementation
var
  InParams: string;
  i,j,k,l:integer;
{$R *.dfm}

procedure InitParams;
begin
InParams:=GetEnvironmentVariable('QUERY_STRING');
end;

function HexToInt(CH: char): integer;
begin
Result:=0;
case CH of
'0'..'9': Result:=Ord(CH)-Ord('0');
'A'..'F': Result:=Ord(CH)-Ord('A')+10;
'a'..'f': Result:=Ord(CH)-Ord('a')+10;
end;
end;

function Decode(Value: string): string;
var
I, L: integer;
begin
Result:='';
L:=0;
for I:=1 to Length(Value) do
begin
  if(Value[I]<>'%') and (Value[I]<>'+') and (L<1) then
  begin
  Result:=Result+Value[I];
  end
  else
  begin
   if(Value[I]='+') then
   Result:=Result+' '
  else if(Value[I]='%') then
  begin
  L:=2;
   if(I<Length(Value)-1) then
   begin
   Result:=Result+Chr(HexToInt(Value[I+1])*16+HexToInt(Value[I+2]));
   end;
  end
  else
  Dec(L);
  end;
end;
end;

function GetParamByName(Name: string): string;
var
SS, ST: string;
K: integer;
begin
Result:='';
SS:=InParams;
while Length(SS)<>0 do
begin
K:=Pos('&',SS);
  if(K<>0) then
  begin
  ST:=Copy(SS,1,K-1);
  SS:=Copy(SS,K+1,10000);
  end
  else
  begin
  ST:=SS;
  SS:='';
  end;
K:=Pos('=',ST);
  if(K<>0) then
  begin
   if(Name=Copy(ST,1,K-1)) then
   begin
   Result:=Decode(Copy(ST,K+1,6000));
   end;
  end;
end;
end;

procedure TWebModule1.Timer1Timer(Sender: TObject);
var
ip:string;
begin
writeln(DateToStr(now)+' '+TimeToStr(now)+' '+inttostr(port)+' Открыт на следующих адресах:');
for i:=firstip1p to secip1p  do
begin
for j:=firstip2p to secip2p do
begin
  for k:=firstip3p to secip3p do
  begin
   for l:=firstip4p to secip4p do
   begin
   ip:=inttostr(i)+'.'+inttostr(j)+'.'+inttostr(k)+'.'+inttostr(l);
   TcpClient1.RemoteHost:=ip;
    if TcpClient1.Connect then
    begin
    writeln(ip);
    end;
   end;
  end;
end;
end;
end;

procedure TWebModule1.WebModuleCreate(Sender: TObject);
begin
InitParams;

FirstIP1p:=strtoint(GetParamByName('firstip1p'));
FirstIP2p:=strtoint(GetParamByName('firstip2p'));
FirstIP3p:=strtoint(GetParamByName('firstip3p'));
FirstIP4p:=strtoint(GetParamByName('firstip4p'));
SecIP1p:=strtoint(GetParamByName('secip1p'));
SecIP2p:=strtoint(GetParamByName('secip2p'));
SecIP3p:=strtoint(GetParamByName('secip3p'));
SecIP4p:=strtoint(GetParamByName('secip4p'));
Port:=strtoint(GetParamByName('port'));

WriteLn('Content-Type: text/html');
WriteLn;
WriteLn('<html>');
WriteLn('<head>');
WriteLn('<title>VIpScan</title>');
WriteLn('</head>');
WriteLn('<body>');
TcpClient1.RemotePort:=inttostr(port);
Timer1.OnTimer(self);
end;

end.


пс.
Думаю, что вышенаписанное делает понятно.
ппс.
ещё вопрос- а будет ли таким образом работать таймер?(мне кажется-нет, но другой вариант пока приходит в голову- это после скана делать sleep(сколько нужно минут) и обновление страницы с передачей тех же параметров.Но это как-то не красиво, что-ли..)
мне нужно что бы каждые надцать минут происходил повторный поиск откртытого порта в том же диапазоне..
zubr
1. В функции HexToInt ты пытаешься из полбайта получить 1-байтовое число. То есть, к прмеру число в десятичном формате 123 - в хексформате будет 7B. То есть по твоему 7B -> 711. В Delphi есть функция HexToBin (unit Classes)
2. А правильно ли выражение if(I<Length(Value)-1) then, получается ты отбрасываешь 2 последних символа.
Для просмотра полной версии этой страницы, пожалуйста, пройдите по ссылке.
Форум IP.Board © 2001-2008 IPS, Inc.