home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / whois.zip / whois.cmd < prev   
OS/2 REXX Batch file  |  1993-04-13  |  2KB  |  87 lines

  1. /* REXX Whois Client
  2.    (C) 1993 by Steve Luzynski
  3.  
  4.    Revision history:
  5.    V.1 - Initial Release
  6.  
  7.    This program requires the rxSock dll function library, available
  8.    anywhere IBM EWS is found.
  9. */
  10.  
  11. trace on
  12.  
  13. parse arg info .
  14.  
  15. if (info = "") then
  16. do
  17.   say "Please enter a name to look up on the command line."
  18.   say "as in:  WHOIS Steve"
  19.   exit 1
  20. end
  21.  
  22. /* setup socket package */
  23. if RxFuncQuery("SockLoadFuncs") then
  24. do
  25.   rc = RxFuncAdd("SockLoadFuncs", "RxSock", "SockLoadFuncs")
  26.   rc = SockLoadFuncs()
  27. end
  28.  
  29. /* get whois server address */
  30. rc = SockGetHostByName("whois", "host.!")
  31. if (rc = 0) then
  32. do
  33.   say "Unable to resolve name of whois server."
  34.   exit
  35. end
  36.  
  37. server = host.!addr
  38.  
  39. say "Looking up" info "on" server "..."
  40.  
  41. /* open a socket to the server */
  42. sock = SockSocket("AF_INET", "SOCK_STREAM", "IPPROTO_TCP")
  43. if (sock = -1) then
  44. do
  45.   say "Error opening socket: " errno
  46.   exit
  47. end
  48.  
  49. /* connect to whois server */
  50. server.!family = "AF_INET"
  51. server.!port   = 43
  52. server.!addr   = server
  53.  
  54. rc = SockConnect(sock, "server.!")
  55. if (sock = -1) then
  56. do
  57.   say "Error connecting socket: " errno
  58.   exit
  59. end
  60.  
  61. data = info || d2c(13) || d2c(10)
  62. i = SockSend(sock, data)
  63. if (errno <> 0) then
  64. do
  65.   SockSoClose(sock)
  66.   exit 1
  67. end
  68. if (i <= 0) then
  69. do
  70.  SockSoClose(sock)
  71.  say "Connection closed by server."
  72.  exit 1
  73. end
  74.  
  75. do until rc <= 0
  76.    rc = SockRecv(sock, "data", 8000)
  77.    say data
  78. end
  79.  
  80. rc = SockSend(sock, "quit")
  81. rc = SockSoClose(sock)
  82. exit
  83.  
  84.  
  85.  
  86.  
  87.