home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / disdns.zip / disdns.cmd
OS/2 REXX Batch file  |  1999-02-25  |  4KB  |  158 lines

  1. /* program to convert netscape.hst to hosts file */
  2. /* This code is far from optimized.  Just did a quicky because after downloading a SHAREWARE
  3.     product that was to convert my bookmark.htm file it reached it's 'limit' while doing the conversion
  4.     and erased my HOSTS file.  I only had only about a dozen entries for various machines that I have to
  5.     maintain, but to erase MY HOSTS file!!!!  So screw it I figured, I'd write my own that could be free,
  6.     somewhat fast, could be set to run upon startup so it could continue to update my hosts file without
  7.     my having to do anything, and best of all just do the trick to speed up net access by bypassing DNS 
  8.     servers.  Anyway if you have read all of this, it is obvious you have less of a life than I.
  9.  
  10.     If you have any suggestions, comments, or questions I can be reached at dodge@disisit.com
  11. */
  12. call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysloadFuncs'
  13. call SysLoadFuncs
  14.  
  15. parse arg ext
  16.  
  17. IF ext='' THEN ext='\netscape.hst'
  18.  
  19. tmp=TRANSLATE(ext)
  20. IF tmp='HELP' | tmp='-H' | tmp='/?' | tmp='-?' THEN DO
  21.     SAY 'Dynamic Information Systems'
  22.     SAY 'http://www.disisit.com'
  23.     SAY 'REXX rules and OS/2 is da bomb'
  24.     SAY '2/24/99  This program is FREE and I will be held harmless for any and all'
  25.     SAY 'damage that may occur for the proper use or misuse of this code.'
  26.     SAY 'disdns will search for all netscape.hst by default on current drive.  '
  27.     SAY "disdns will convert all http://addresses to its' numeric address"
  28.     SAY "and populate your HOSTS file for speedier 'net access"
  29.     SAY 'Usage:'
  30.     SAY '   disdns [filename]'
  31.     SAY '   default is \netscape.hst'
  32.     SAY '   you may also use bookmark.htm files'
  33. END
  34. b=X2C(1A)
  35. tab=X2C(09)
  36. call SysFileTree ext, 'file', 'S'
  37. flag=0
  38. t=''
  39. cr=D2C(13)
  40. lf=D2C(10)
  41. crlf=cr||lf
  42. alpha_s=C2D('A')
  43. alpha_e=C2D('Z')
  44. num_s=C2D('0')
  45. num_e=C2D('9')
  46. Qfetch = rxqueue('create')
  47.  
  48. /* FIND HOSTS FILE */
  49. '@set etc| rxqueue 'Qfetch
  50. call rxqueue 'set', Qfetch
  51. c=0
  52. do while queued() \=0
  53.     pull t
  54.     PARSE VAR t '=' p
  55.     IF p='(Null)' THEN DO
  56.         SAY 'HOSTS directory not found you need to have a SET ETC=<drive>:\MPTN\ETC in your CONFIG.SYS file.'    
  57.         EXIT
  58.     END
  59.     IF RIGHT(p,1)\='\' THEN p=p'\'
  60. END
  61.  
  62. /* FIND USE_HOSTS_FIRST */
  63. '@set USE_HOSTS_FIRST| rxqueue 'Qfetch
  64. call rxqueue 'set', Qfetch
  65. do while queued() \=0
  66.     pull t
  67.     PARSE VAR t '=' px
  68.     IF px='(Null)' THEN DO
  69.         SAY 'You need to have a SET USE_HOSTS_FIRST=1 in your CONFIG.SYS file.'    
  70.         EXIT
  71.     END
  72. END
  73.  
  74.  
  75. /* READ IN HOSTS FILE NOT TO DUPLICATE ENTRY'S */
  76. a.0=0
  77. i=1
  78. IF STREAM(p'hosts', 'c', 'query exists') \= '' THEN DO FOREVER
  79.     tmp=LINEIN(p'hosts')
  80.     IF tmp='' THEN LEAVE
  81.     tmp=TRANSLATE(tmp,' ',tab)
  82.     PARSE VAR tmp num ' ' a.i
  83.     a.i=TRANSLATE(a.i)
  84.     a.0=i
  85.     i=i+1
  86. END
  87. IF i>1 THEN CALL LINEOUT p'hosts'
  88.  
  89.  
  90.  
  91. do i=1 to file.0
  92.     parse var file.i . . size . name
  93.     name=STRIP(name)
  94.     say 'READING file 'name
  95.     tmp=CHARIN(name,1,size)
  96. /*    say 'length of tmp record .'LENGTH(tmp)'. .'size'.' */
  97.     IF LENGTH(tmp) \= size THEN DO
  98.         say 'Error opening 'name 'please close any applications that may be using this file'
  99.         LEAVE
  100.     END
  101.     DO WHILE POS('://',tmp) > 0 
  102.         PARSE VAR tmp . '://' web '/' tmp
  103.         web=STRIP(web)    
  104.         c_web=TRANSLATE(web)
  105. /*        say 'looking for 'c_web */ 
  106.         skip=0
  107.         DO x=LENGTH(c_web) to 1 BY -1
  108.             v=C2D(SUBSTR(c_web,x,1))
  109.             IF ((v >= alpha_s & v <= alpha_e) | (v >= num_s & v <= num_e) | v=C2D('.') | v=C2D('-') | v=C2D('_')) THEN 
  110.                 nop=nop                
  111.             ELSE DO
  112.                 skip=1
  113.             END
  114.         END 
  115.         IF skip = 0 & LENGTH(c_web) > 2 THEN DO
  116.             IF a.0=0 THEN DO
  117.                 a.1=c_web
  118.                 a.0=1
  119.             END
  120.  
  121.             DO x = 1 to a.0 
  122.                 IF c_web = a.x THEN DO
  123.                     skip=1
  124.                 END
  125.             END
  126.             IF skip=0 THEN DO
  127.                 a.0=a.0+1
  128.                 v=a.0
  129.                 a.v=c_web
  130.                 say web
  131.                 '@nslookup 'web' | rxqueue 'Qfetch
  132.                 call rxqueue 'set', Qfetch
  133.                 c=0
  134.                 do while queued() \=0
  135.                     pull t
  136. /*                    say t */
  137.                     IF POS('ADDRESS',t) > 0  THEN DO
  138.                         c=c+1
  139.                         IF POS('ADDRESS:',t) > 0 THEN PARSE VAR t 'ADDRESS:' ip
  140.                         IF POS('ADDRESSES:',t) > 0 THEN PARSE VAR t 'ADDRESSES:' ip ',' .
  141.                     END
  142.                 END
  143.                 IF c=2 THEN DO
  144.                     ip=STRIP(ip)
  145. /*                    say 'ip ='ip */
  146.                     IF ip \= web THEN Call LINEOUT p'hosts', ip||tab||web
  147.                 END
  148.             END
  149.         END
  150.     END
  151. END
  152. say ' '
  153. say 'Completed you should have speedier net access now!!'
  154. say 'Dynamic Information Systems'
  155. SAY 'http://www.disisit.com'
  156. SAY 'REXX rules and OS/2 is da bomb'
  157. RETURN 0
  158.