PHP Code to find the Server IP Address

This is a php code snippet that can help you to find out the Shared IP/Server IP of the server.

<?php
echo GetServerIP ; 

function IsVPS()
{
    
    $a = '/sbin/ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'';
    exec($a,$c);
    
    if($c[0] == "")
    return true ;
    else
    return false ;
    
}
 
 
function GetServerIP() 
{
    if(IsVPS == true )
    $a = '/sbin/ifconfig venet0:0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'';
    else
    $a = '/sbin/ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'';
    exec($a,$c);
    return $c['0'];
    
}
?>

Leave a Reply

Your email address will not be published.