search
Homephp教程PHP源码php随机生成国内ip地址

获得一个国家所有ip段,随机生成国内ip地址的缩水实现。
注意:  $ip_long数组中后5个值在64位系统中可能是错误的(下面代码中  $ip_long 数组的后五个值在32位系统中为负数,64位系统中为正数,前五个值在64位系统中也可能有错误)
32位系统
echo ip2long(“172.16.1.63″);
结果 -1408237249
64位操作系统
echo ip2long(“172.16.1.63″);

所有ip地址网段下载
http://www.ipaddresslocation.org/ip_ranges/get_ranges.php

缩水随机生成国内ip地址
总共有1600多个网段,只取了其中10个确定是国内的网段
使用了2个php函数
ip2long($ip)把ip转为int
long2ip($int_ip)把int转回ip

<?php
function ip()
{
    $ip_long = array(
        array(&#39;607649792&#39;, &#39;608174079&#39;), // 36.56.0.0-36.63.255.255
        array(&#39;1038614528&#39;, &#39;1039007743&#39;), // 61.232.0.0-61.237.255.255
        array(&#39;1783627776&#39;, &#39;1784676351&#39;), // 106.80.0.0-106.95.255.255
        array(&#39;2035023872&#39;, &#39;2035154943&#39;), // 121.76.0.0-121.77.255.255
        array(&#39;2078801920&#39;, &#39;2079064063&#39;), // 123.232.0.0-123.235.255.255
        array(&#39;-1950089216&#39;, &#39;-1948778497&#39;), // 139.196.0.0-139.215.255.255
        array(&#39;-1425539072&#39;, &#39;-1425014785&#39;), // 171.8.0.0-171.15.255.255
        array(&#39;-1236271104&#39;, &#39;-1235419137&#39;), // 182.80.0.0-182.92.255.255
        array(&#39;-770113536&#39;, &#39;-768606209&#39;), // 210.25.0.0-210.47.255.255
        array(&#39;-569376768&#39;, &#39;-564133889&#39;), // 222.16.0.0-222.95.255.255
        );
    $rand_key = mt_rand(0, 9);
    return $ip = long2ip(mt_rand($ip_long[$rand_key][0], $ip_long[$rand_key][1]));
} 
?>
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment