home *** CD-ROM | disk | FTP | other *** search
/ The Unsorted BBS Collection / thegreatunsorted.tar / thegreatunsorted / misc / remotelg.pas < prev    next >
Pascal/Delphi Source File  |  2001-02-10  |  6KB  |  259 lines

  1. program TelenetHacker;
  2.  
  3. USES
  4.      DOS, ASYNC12, CRT;
  5.  
  6. TYPE
  7.      ModemStuff =
  8.           RECORD
  9.           ComPort,
  10.           Stopbits,
  11.           Databits,
  12.           TimeToWait : byte;
  13.           Parity     : char;
  14.           Baudrate,
  15.           ModemDelay : integer;
  16.           HayesHangup,
  17.           HayesReset,
  18.           HayesInit1,
  19.           HayesInit2,
  20.           HayesDial  : string;
  21.           end;
  22. VAR
  23.      SystemDate,
  24.      SystemTime,
  25.      CR,
  26.      LF,
  27.      CL,
  28.      BS,
  29.      SPACE,
  30.      filename,
  31.      AreaCode     : string;
  32.      done         : boolean;
  33.      ModemRec     : ModemStuff;
  34.  
  35. Procedure TimeDate;
  36. const
  37.      days : array[0 .. 6] of string[3] =
  38.           ('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat');
  39.      months : array[1 .. 12] of string[3] =
  40.           ('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
  41. var
  42.      year,
  43.      month,
  44.      day,
  45.      dayofweek  : word;
  46.      xyear,
  47.      xmonth,
  48.      xday,
  49.      xdayofweek : string;
  50.      hour,
  51.      minute,
  52.      second,
  53.      sec100     : word;
  54.      xhour,
  55.      xminute,
  56.      xsecond,
  57.      xsec100    : string;
  58.  
  59. begin
  60. getdate(year, month, day, dayofweek);
  61. str(year, xyear); xyear := copy(xyear, 3, 2);
  62. str(month, xmonth);
  63. str(day, xday);
  64. str(dayofweek, xdayofweek);
  65. SystemDate := days[dayofweek]+' '+xday+'-'+months[month]+'-'+xyear;
  66.  
  67. gettime(hour, minute, second, sec100);
  68. str(hour, xhour);
  69. str(minute, xminute);
  70. str(second, xsecond);
  71. str(sec100, xsec100);
  72. if hour < 10 then xhour := '0'+xhour;
  73. if minute < 10 then xminute := '0'+xminute;
  74. if second < 10 then xsecond := '0'+xsecond;
  75. SystemTime := xhour+':'+xminute+':'+xsecond;
  76. end;
  77.  
  78.  
  79. procedure InitComport;
  80. begin
  81. closecom(ModemRec.Comport);
  82. if NOT comexist(ModemRec.Comport) then
  83.      begin
  84.      writeln('Comport does not exist');
  85.      halt;
  86.      end;
  87. if NOT opencom(ModemRec.Comport, 2000, 2000) then
  88.      begin
  89.      writeln('Comport fails to open');
  90.      halt;
  91.      end;
  92. ModemRec.Baudrate := 1200;
  93. comparams(ModemRec.Comport,
  94.           ModemRec.Baudrate,
  95.           ModemRec.Databits,
  96.           ModemRec.Parity,
  97.           ModemRec.Stopbits);
  98. if NOT ctsstat(ModemRec.Comport) then
  99.      begin
  100.      writeln('CTS not active.');
  101.      end;
  102. if NOT dsrstat(ModemRec.Comport) then
  103.      begin
  104.      writeln('DSR not active.');
  105.      end;
  106. softhandshake(ModemRec.Comport, true, ^Q, ^S);
  107. end;
  108.  
  109. function ModemOK : boolean;
  110. var
  111.      ch : char;
  112.      O_counter,
  113.      K_counter : longint;
  114.      st : string;
  115.      forever : boolean;
  116. begin
  117. forever := false;
  118. ModemOK := false;
  119. O_counter := 0;
  120. K_counter := 0;
  121. st := '';
  122. repeat
  123.      if O_counter > 150000 then exit;
  124.      inc(O_counter);
  125.      ch := comreadch(ModemRec.Comport);
  126.      if ch = 'O' then
  127.           begin
  128.           writeln;
  129.           write('O');
  130.           K_counter := 0;
  131.           st := st + ch;
  132.           repeat
  133.                if K_counter > 150000 then exit;
  134.                inc(K_counter);
  135.                ch := comreadch(ModemRec.Comport);
  136.                if ch = 'K' then
  137.                     begin
  138.                     writeln('K');
  139.                     st := st + ch;
  140.                     ModemOK := true;
  141.                     clearcom(ModemRec.Comport, 'B');
  142.                     exit;
  143.                     end;
  144.           until forever;
  145.           end;
  146. until forever;
  147. end;
  148.  
  149. function ModemInitStringSent : boolean;
  150. begin
  151. comwritewithdelay(ModemRec.Comport, '++++++', ModemRec.ModemDelay);
  152. ModemInitStringSent := false;
  153. repeat
  154.      ModemRec.ModemDelay := ModemRec.ModemDelay + 20;
  155.      if ModemRec.ModemDelay > 500 then
  156.           begin
  157.           writeln('Modem NOT responding.');
  158.           halt;
  159.           end;
  160.      comwritewithdelay(ModemRec.Comport, ModemRec.HayesReset + CR, ModemRec.ModemDelay);
  161. until ModemOK;
  162. delay(ModemRec.ModemDelay);
  163.  
  164. repeat
  165.      ModemRec.ModemDelay := ModemRec.ModemDelay + 20;
  166.      if ModemRec.ModemDelay > 500 then
  167.           begin
  168.           writeln('Modem NOT responding.');
  169.           halt;
  170.           end;
  171.      comwritewithdelay(ModemRec.Comport, ModemRec.HayesInit1 + CR, ModemRec.ModemDelay);
  172. until ModemOK;
  173. delay(ModemRec.ModemDelay);
  174.  
  175. repeat
  176.      ModemRec.ModemDelay := ModemRec.ModemDelay + 20;
  177.      if ModemRec.ModemDelay > 500 then
  178.           begin
  179.           writeln('Modem NOT responding.');
  180.           halt;
  181.           end;
  182.      comwritewithdelay(ModemRec.Comport, ModemRec.HayesInit2 + CR, ModemRec.ModemDelay);
  183. until ModemOK;
  184. delay(ModemRec.ModemDelay);
  185. ModemInitStringSent := True;
  186. end;
  187.  
  188.  
  189. function AllCaps(st : string) : string;
  190. var
  191.      x : integer;
  192. begin
  193. for x := 1 to length(st) do
  194.      begin
  195.      st[x] := upcase(st[x]);
  196.      end;
  197. AllCaps := st;
  198. end;
  199.  
  200. function DialRT : boolean;
  201. var
  202.      timeout : integer;
  203. begin
  204. DialRT := false;
  205. timeout := 0;
  206. comwritewithdelay(ModemRec.Comport, ModemRec.HayesDial+'xxxxxxx'+CR, ModemRec.ModemDelay);
  207. repeat
  208.      delay(5000);
  209.      inc(timeout);
  210.      if timeout > ModemRec.TimeToWait then exit;  (* the dial failed... *)
  211. until DCDstat(ModemRec.Comport);
  212. DialRT := true;
  213. end;
  214.  
  215. Procedure Send(filename:string);
  216. var
  217.      filevar:text;
  218.      oneline:string;
  219. begin
  220. assign(filevar, filename);
  221. reset(filevar);
  222. repeat
  223.      ReadLn(filevar, oneline);
  224.      ComWriteln(ModemRec.Comport, oneline); WriteLn(Oneline);
  225.      delay(2000);
  226. until eof(filevar);
  227. delay(5000);
  228. end;
  229.  
  230. begin
  231. ModemRec.ComPort      := 2;
  232. ModemRec.Stopbits     := 1;
  233. ModemRec.Databits     := 8;
  234. ModemRec.TimeToWait   := 6;
  235. ModemRec.Parity       := 'N';
  236. ModemRec.Baudrate     := 1200;
  237. ModemRec.ModemDelay   := 200;
  238. ModemRec.HayesHangup  := 'ATH';
  239. ModemRec.HayesReset   := 'ATZ';
  240. ModemRec.HayesInit1   := 'ATM1';
  241. ModemRec.HayesInit2   := 'ATM1';
  242. ModemRec.HayesDial    := 'ATDT';
  243.  
  244. CR           := #13;
  245. LF           := #10;
  246. CL           := CR+LF;
  247. BS           := #8;
  248. SPACE        := #32;
  249.  
  250. done         := false;
  251. TimeDate;
  252. InitComport;
  253. Repeat Until ModemInitStringSent;
  254. if DialRT then
  255.      begin
  256.      Send('c:\waffle\words\netinfo');
  257.      CloseCom(ModemRec.Comport);
  258.      end
  259. end.