IPCALC
[ class tree: IPCALC ] [ index: IPCALC ] [ all elements ]

Sample code of IPCLAC class

  1. <?php
  2.  
  3. require_once 'ipcalc.php';
  4.  
  5. function title ($s{
  6.     printf (' * IPCALC::%-20s => '$s);
  7. }
  8. function result ($bool{
  9.     printf ("%s\n"$bool 'Success' 'Failed');
  10. }
  11.  
  12. echo "** Test IPCALC PHP pear API test\n\n";
  13.  
  14. $ip new IPCALC;
  15.  
  16. title ('ip2long');
  17. $src  '222.222.222.222';
  18. $dest 3739147998;
  19. $test $ip->ip2long ($src);
  20.  
  21. result ($dest == $test);
  22.  
  23. title ('valid_ipv4_addr');
  24. $test $ip->valid_ipv4_addr ('1.1.1.1 :');
  25. result ($test);
  26.  
  27. title ('prefix2mask');
  28. $test $ip->prefix2mask (26);
  29. result ($test == '255.255.255.192');
  30.  
  31. title ('mask2prefix');
  32. $test $ip->mask2prefix ('255.255.255.192');
  33. result ($test == 26);
  34.  
  35. title ('network');
  36. $test $ip->network ('222.222.222.222'26);
  37. result ($test == '222.222.222.192');
  38.  
  39. title ('boradcast');
  40. $test $ip->broadcast ('222.222.222.222'26);
  41. result ($test == '222.222.222.255');
  42.  
  43. title ('guess_prefix');
  44. $test $ip->guess_prefix ('222.222.222.193''222.222.222.229');
  45. result ($test === 26);
  46.  
  47. title ('guess_netmask');
  48. $test $ip->guess_netmask ('222.222.222.193''222.222.222.229');
  49. result ($test === '255.255.255.192');
  50.  
  51. echo "\n\n";
  52. ?>

Documentation generated on Tue, 14 May 2019 02:00:07 +0900 by phpDocumentor 1.4.4