class_ConsoleTools.php

Go to the documentation of this file.
00001 <?php
00024 class ConsoleTools extends BaseFrameworkSystem {
00030         protected function __construct () {
00031                 // Call parent constructor
00032                 parent::__construct(__CLASS__);
00033         }
00034 
00040         public static function aquireSelfIPAddress () {
00041                 // Local IP by default
00042                 $ip = "127.0.0.1";
00043 
00044                 // Get a new instance
00045                 $helper = new ConsoleTools();
00046 
00047                 try {
00048                         // Get a file pointer
00049                         $io = FrameworkFileInputPointer::createFrameworkFileInputPointer("/etc/hostname");
00050 
00051                         // Read the file
00052                         $hostname = trim($io->readFromFile());
00053                         $helper->debugOutput(sprintf("[%s:] Our host name is: <span class=\"data\">%s</span>",
00054                                 $helper->__toString(),
00055                                 $hostname
00056                         ));
00057 
00058                         // Close the file
00059                         $io->closeFile();
00060 
00061                         // Resolve it
00062                         $ipResolved = gethostbyname($hostname);
00063                         if (($ipResolved !== false) && ($ipResolved != $hostname)) {
00064                                 // Okay, this works!
00065                                 $ip = $ipResolved;
00066 
00067                                 // Debug message
00068                                 $helper->debugOutput(sprintf("[%s:] Resolved IP address is: <span class=\"data\">%s</span>\n",
00069                                         $helper->__toString(),
00070                                         $ip
00071                                 ));
00072                         }
00073                 } catch (FrameworkException $e) {
00074                         // Do nothing here
00075                 }
00076 
00077                 // Return the IP address
00078                 return $ip;
00079         }
00080 }
00081 
00082 // [EOF]
00083 ?>

Generated on Mon Dec 8 01:06:45 2008 for Ship-Simulator by  doxygen 1.5.6