home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / ipcfg12.zip / ipconfig.cmd next >
OS/2 REXX Batch file  |  1999-10-13  |  3KB  |  150 lines

  1. /* REXX routine to emulate the Windows "ipconfig" command */
  2.  
  3. /* This routine only handles interfaces which are up */
  4. /* You may contact me via email to jlemay@njmc.com */
  5. /* Revision 1.2 */
  6.  
  7. '@echo off'
  8.  
  9. parse arg iFace
  10.  
  11. didit = 0  /* For display of "OS/2 IP Configuration" line */
  12.  
  13. /* If no parm, give all! */
  14. IF iFace = '' THEN
  15.     iFace = 'all'
  16.  
  17. IF iFace = 'all' 
  18.     THEN
  19.         DO
  20.             CALL sublan0
  21.             CALL subppp0
  22.               EXIT
  23.           END
  24.  
  25. IF iFace = 'lan0' 
  26.     THEN 
  27.         Do
  28.             CALL sublan0
  29.             EXIT
  30.         End
  31.  
  32. IF iFace = 'PPP0' 
  33.     THEN 
  34.         Do
  35.             CALL subppp0
  36.             EXIT
  37.         End
  38.  
  39. IF iFace = 'ppp0'     /* Dirty way to handle case sensitivity */
  40.     THEN 
  41.         Do
  42.             CALL subppp0
  43.             EXIT
  44.         End
  45.  
  46. /* Handle improper arg passed */
  47. SAY
  48. SAY '          OS/2 IP Configuration Display Utility version 1.1'
  49. SAY '          -------------------------------------------------'
  50. SAY
  51. SAY 'Usage: IPCONFIG <interface>'
  52. SAY
  53. SAY 'Supported Interfaces in this version are PPP0 and lan0.'
  54. SAY
  55. SAY '''IPCONFIG all'' may also be used to display info for all'
  56. SAY 'active interfaces. (currently limited to PPP0 and lan0)'
  57. SAY
  58. EXIT
  59.  
  60. /* Begin sublan0 */
  61. sublan0:
  62.     
  63.     ActiFace = 'lan0'
  64.     'ifconfig lan0 > lan0.txt'
  65.     'netstat -r > route.txt'
  66.  
  67.             Do WHILE lines(lan0.txt)
  68.                 line = LineIn(lan0.txt)
  69.                 IF Pos('inet', line) >< 0 THEN
  70.                     PARSE VAR line 'inet ' ip ' netmask x' mask ' broadcast '
  71.             END
  72.  
  73.             Do WHILE lines(route.txt)
  74.                 line = LineIn(route.txt)
  75.                 IF Pos(ip, line) >< 0 THEN
  76.                     DO
  77.                         PARSE VAR line net gw garbage
  78.                         IF SUBSTR(net, 1, 3) = SUBSTR(ip, 1, 3)
  79.                             THEN router = gw
  80.                     END        
  81.             END    
  82.         
  83.     CALL DISPLAY
  84.  
  85. RETURN
  86.  
  87. /* Begin subppp0 */
  88. subppp0:
  89.  
  90.     ActiFace = 'PPP0'
  91.     'ifconfig PPP0 > PPP0.txt'
  92.     'netstat -r > route.txt'
  93.  
  94.             Do WHILE lines(PPP0.txt)
  95.                 line = LineIn(PPP0.txt)
  96.                 IF Pos('inet', line) >< 0 THEN
  97.                     PARSE VAR line 'inet ' ip ' netmask x' mask ' broadcast '
  98.             END
  99.             
  100.             Do WHILE lines(route.txt)
  101.                 line = LineIn(route.txt)
  102.                 IF Pos('default', line) >< 0 THEN
  103.                     PARSE VAR line 'default   'router '    ' garbage
  104.             END            
  105.  
  106.     CALL DISPLAY
  107.  
  108. RETURN
  109.  
  110. /* Begin DISPLAY sub */
  111. DISPLAY:
  112.  
  113.     oct1 = Substr(mask, 1, 2)
  114.     oct2 = Substr(mask, 3, 2)
  115.     oct3 = Substr(mask, 5, 2)
  116.     oct4 = Substr(mask, 7, 2)
  117.  
  118.     /* This line courtesy of Undernet's NewOrder - Thanks Jason! */
  119.     decMask = x2D(oct1)||.||x2D(oct2)||.||x2D(oct3)||.||x2D(oct4)
  120.  
  121.     /* Display Results */
  122.     If didit >< 1
  123.         THEN
  124.             DO
  125.                 SAY
  126.                 SAY
  127.                 SAY 'OS/2 IP Configuration'
  128.             didit = 1
  129.             END
  130.         
  131.     SAY
  132.     SAY 'Interface: 'ActiFace
  133.     SAY 
  134.     SAY '        IP Address   .   .   .   .   :  'ip
  135.     SAY '        Subnet Mask  .   .   .   .   :  'decmask
  136.     SAY '        Default Gateway  .   .   .   :  'router 
  137.     
  138.     /* Cleanup! */
  139.  
  140.     CALL LineOut PPP0.txt
  141.     'del PPP0.txt'
  142.  
  143.     CALL LineOut lan0.txt
  144.     'del lan0.txt'
  145.  
  146.     CALL LineOut route.txt
  147.     'del route.txt'
  148.  
  149. RETURN
  150.