PHP get IP, MAC address function

Source: Internet
Author: User
Tags get ip
Parameter $aitype value: 1:ip,2:mac,3:ip+mac
Returns the return string: address string

<?php
function getclientaddr ($AiType =0)
{
$sMac = "";
$ip = getenv ("REMOTE_ADDR");
$ip 1 = getenv ("Http_x_forwarded_for");
$ip 2 = getenv ("Http_client_ip");
($ip 1)? $ip = $ip 1:null;
($ip 2)? $ip = $ip 2:null;
if ($AiType > 1)
{
$SCMD = "Nbtstat-a". $ip;
$sString = Shell_exec ($SCMD);
$aTemp = Split ("=", $sString);
$sMac = Trim ($aTemp [count ($aTemp)-1]);
}
Switch ($AiType)
{
Case 0:
$sResult = "";
Break
Case 1:
$sResult = $ip;
Break
Case 2:
$sResult = $sMac;
Break
Case 3:
$sResult = $ip. " " . $sMac;
Break
Default
$sResult = "";
Break
}
return $sResult;
}
?>

Parameter $aitype value: 1:ip,2:mac,3:ip+mac
Returns the return string: address string

<?php
function getclientaddr ($AiType =0)
{
$sMac = "";
$ip = getenv ("REMOTE_ADDR");
$ip 1 = getenv ("Http_x_forwarded_for");
$ip 2 = getenv ("Http_client_ip");
($ip 1)? $ip = $ip 1:null;
($ip 2)? $ip = $ip 2:null;
if ($AiType > 1)
{
$SCMD = "Nbtstat-a". $ip;
$sString = Shell_exec ($SCMD);
$aTemp = Split ("=", $sString);
$sMac = Trim ($aTemp [count ($aTemp)-1]);
}
Switch ($AiType)
{
Case 0:
$sResult = "";
Break
Case 1:
$sResult = $ip;
Break
Case 2:
$sResult = $sMac;
Break
Case 3:
$sResult = $ip. " " . $sMac;
Break
Default
$sResult = "";
Break
}
return $sResult;
}
?>


The above is the PHP get IP, MAC address function content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.