YesYo.com MintState Forums
뒤로    YesYo.com MintState BBS > Tech > PHP
검색
멤버이름    오토
비밀번호 
 

[Function] ip2long, long2ip

페이지 정보

작성자 MintState 댓글 0건 조회 13,915회 작성일 08-11-17 10:28

본문

[Function] ip2long, long2ip

ip2long — Converts a string containing an (IPv4) Internet Protocol dotted address into a proper address

ex)
<?php
$ip = gethostbyname('www.example.com');
$long = ip2long($ip)
if ($long == -1 || $long === FALSE) {
    echo 'Invalid IP, please try again';
} else {
	$out = "The following URLs are equivalent:<br />\n";
	$out .= 'http://www.example.com/, http://' . $ip . '/, and http://' . sprintf("%u", $long) . "/<br />\n";
	echo $out;
}
?>


long2ip — Converts an (IPv4) Internet network address into a string in Internet standard dotted format

If the function doesn't exist:
<?
    if (!function_exists("long2ip")) {
        function long2ip($long) {
            // Valid range: 0.0.0.0 -> 255.255.255.255
            if ($long < 0 || $long > 4294967295) return false;
            $ip = "";
            for ($i=3;$i>=0;$i--) {
                $ip .= (int)($long / pow(256,$i));
                $long -= (int)($long / pow(256,$i))*pow(256,$i);
                if ($i>0) $ip .= ".";
            }
            return $ip;
        }
    }
?> 


$a = ip2long('192.168.0.4));
$b = long2ip($a);
echo $a . "_____________" . $b;

댓글목록

등록된 댓글이 없습니다.

Total 165건 5 페이지
PHP 목록
번호 제목 글쓴이 조회 날짜
65 MintState 11484 11-10
64 MintState 20043 11-10
63 MintState 12874 11-10
62 MintState 13017 11-10
61 MintState 20849 11-10
60 MintState 12643 11-10
59 MintState 14608 11-10
58 MintState 14711 11-10
57 MintState 15885 11-10
56 MintState 30631 11-10
55 MintState 12515 11-10
54 MintState 21281 11-10
53 MintState 17147 11-10
52 MintState 16224 11-10
51 MintState 14563 11-10
50 MintState 14585 11-10
49 MintState 16250 11-10
열람중 MintState 13916 11-17
47 MintState 17339 11-17
46 MintState 12335 11-17
45 MintState 22408 11-17
44 MintState 17064 11-17
43 MintState 15446 02-17
42 MintState 16467 02-17
41 MintState 16140 02-23
게시물 검색
모바일 버전으로 보기
CopyRight ©2004 - 2024, YesYo.com MintState. ™