php 获取自己的公网IP

<?php
$externalContent = file_get_contents('http://checkip.dyndns.com/');
preg_match('/Current IP Address: \[?([:.0-9a-fA-F]+)\]?/', $externalContent, $m);
$externalIp = $m[1];
echo $externalIp;

 

posted @ 2016-01-22 23:27  johnsonshu  阅读(2094)  评论(0编辑  收藏  举报