home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 28 / amigaformatcd28.iso / -seriously_amiga- / comms / other / rxsocket / examples / pst.rexx < prev    next >
Encoding:
OS/2 REXX Batch file  |  1998-05-09  |  1.1 KB  |  59 lines

  1. /*
  2.      A "not so good" macro to scan tcp ports.
  3.  
  4.      Usage: pst <host> <fromPort/N> <toPort/N>"
  5. */
  6.  
  7. parse arg host low hi .
  8.  
  9. if ~show("L","rxsocket.library") then
  10.     if ~addLib("rxsocket.library",0,-30) then do
  11.         say "can't find rxsocket.library"
  12.         exit
  13.     end
  14.  
  15. if host=="" | host== "?" | low=="" | hi=="" then do
  16.     say "Usage: pst <host> <fromPort/N> <toPort/N>"
  17.     exit
  18. end
  19.  
  20. if ~DataType(low,NUM) then do
  21.     say "pst: bad number fromPort"
  22.     exit
  23. end
  24.  
  25. if ~DataType(hi,NUM) then do
  26.     say "pst: bad number toPort"
  27.     exit
  28. end
  29.  
  30. if hi<low then do
  31.     say "pst: fromPort must be less than toPort"
  32.     exit
  33. end
  34.  
  35. sin.ADDRADDR = resolve(host)
  36. if sin.ADDRADDR==-1 then do
  37.     say "pst: no host <" || host || ">"
  38.     exit
  39. end
  40.  
  41. sin.ADDRFAMILY = "INET"
  42.  
  43. do sin.ADDRPORT = low to hi
  44.  
  45.     sock = socket("INET","STREAM","IP")
  46.     if sock<0 then do
  47.         say "pst: no socket (" "" errno() || ")"
  48.         exit
  49.     end
  50.  
  51.     if connect(sock,"SIN")>=0 then
  52.         if GetServByPort("SERV",sin.ADDRPORT,"tcp") then
  53.             say "pst: servizio" serv.servname "(" || sin.ADDRPORT ||")" "aperto"
  54.         else say "pst: porta" sin.ADDRPORT "aperta"
  55.  
  56.     call CloseSocket(sock)
  57.  
  58. end
  59.