PHPackages                             mantoufan/yzhanip - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. mantoufan/yzhanip

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

mantoufan/yzhanip
=================

Crawl, match, parse IP or IP range, check if IP or range is in another range. Support IPv4, IPv6, IP Interval, Wildcard and CIDR. Check if IP is Cloudflare node IP, Google bot IP. 爬取，正则匹配，解析 IP 和 IP 范围，检测 IP 或范围是否在另一个范围中。支持 IPv4，IPv6，区间、通配符或 CIDR 表示的 IP 范围。检测 IP 是否是 Cloudflare 节点或 Google 漫游器 IP

1.0.1(3y ago)541.4k3MITPHPPHP &gt;=5.4

Since Sep 5Pushed 3y ago1 watchersCompare

[ Source](https://github.com/mantoufan/yzhanIP)[ Packagist](https://packagist.org/packages/mantoufan/yzhanip)[ RSS](/packages/mantoufan-yzhanip/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (2)Versions (3)Used By (0)

YZhanIP
=======

[](#yzhanip)

[![Packagist License](https://camo.githubusercontent.com/66899b9dcd1459a6be77aafa02a557410fb095f08aab5a7a7b9f757fdc9f51d5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6d616e746f7566616e2f797a68616e69703f763d31)](https://camo.githubusercontent.com/66899b9dcd1459a6be77aafa02a557410fb095f08aab5a7a7b9f757fdc9f51d5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6d616e746f7566616e2f797a68616e69703f763d31) [![Packagist PHP Version Support](https://camo.githubusercontent.com/6f555da96c9dee770238c952a4fd18072eab91aa123a394afdc9edaa97f33968/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6d616e746f7566616e2f797a68616e6970)](https://camo.githubusercontent.com/6f555da96c9dee770238c952a4fd18072eab91aa123a394afdc9edaa97f33968/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6d616e746f7566616e2f797a68616e6970) [![Test Coverage](./badge-coverage.svg)](./badge-coverage.svg)
Crawl, match, parse IP or IP range, check if IP or range is in another range
Support IPv4, IPv6, IP Interval, Wildcard and CIDR
Check if IP is Cloudflare node IP, Google bot IP
爬取，正则匹配，解析 IP 和 IP 范围，检测 IP 或范围是否在另一个范围中
支持 IPv4，IPv6，区间、通配符或 CIDR 表示的 IP 范围
检测 IP 是否是 Cloudflare 节点或 Google 漫游器 IP

Install 安装
----------

[](#install-安装)

```
composer require mantoufan/yzhanip
```

Usage 使用
--------

[](#usage-使用)

### In 包含

[](#in-包含)

```
use YZhanIP\YZhanIP;
```

#### Check if an IP is included in an IP range

[](#check-if-an-ip-is-included-in-an-ip-range)

#### 检测一个 IP 是否被 IP 范围包含

[](#检测一个-ip-是否被-ip-范围包含)

```
(new YZhanIP('127.0.0.1'))->in(new YZhanIP('127.0.0.*')); // true, new YZhanIP can be omitted
(new YZhanIP('127.0.0.1'))->in('127.0.0.1-127.0.0.30'); // true
(new YZhanIP('127.0.0.1'))->in('127.0.0.*'); // true
(new YZhanIP('127.0.0.1'))->in('127.0.0.1/21'); // true
(new YZhanIP('2001:4860:4801::af88'))->in('2001:4860:4801::af88-2001:4860:4801::afff'); // true
(new YZhanIP('2001:4860:4801::af88'))->in('2001:4860:*::af88'); // true
(new YZhanIP('2001:4860:4801::af88'))->in('2001:4860:4801::af88/7'); // true
```

#### Check if an IP range is included in an IP range

[](#check-if-an-ip-range-is-included-in-an-ip-range)

#### 检测一个 IP 范围被另一个 IP 范围包含

[](#检测一个-ip-范围被另一个-ip-范围包含)

```
(new YZhanIP('127.0.0.1-127.0.0.30'))->in('127.0.0.*'); // true
(new YZhanIP('127.0.0.*'))->in('127.0.0.1/21'); // true
(new YZhanIP('2001:4860:4801::af88-2001:4860:4801::afff'))->in('2001:4860:*::af88'); // true
(new YZhanIP('2001:4860:*::af88'))->in('2001:4860:4801::af88/7'); // true
```

#### Check if a mixed array of IP / IP ranges is included in another mixed array of IP / IP ranges

[](#check-if-a-mixed-array-of-ip--ip-ranges-is-included-in-another-mixed-array-of-ip--ip-ranges)

#### 检测一组 IP / IP 范围混合数组被另一组 IP / IP 范围混合数组包含

[](#检测一组-ip--ip-范围混合数组被另一组-ip--ip-范围混合数组包含)

```
(new YZhanIP(['127.0.0.1', '127.0.0.1-127.0.0.30', '127.0.0.*']))->in('127.0.0.1/21'); // true
(new YZhanIP(['2001:4860:4801::af88', '2001:4860:4801::af88-2001:4860:4801::afff', '2001:4860:*::af88']))->in('2001:4860:4801::af88/7'); // true
```

### ToString 转为字符串

[](#tostring-转为字符串)

#### IP: to minimal form IP range: Wildcard / CIDR to Interval

[](#ip-to-minimal-form-ip-range-wildcard--cidr-to-interval)

#### IP：转为最简形式，IP 范围：区间、通配符、CIDR 转为区间

[](#ip转为最简形式ip-范围区间通配符cidr-转为区间)

```
(new YZhanIP(['127.0.0.*', '127.0.0.1/21']))->toString(); // 127.0.0.0-127.0.0.255,127.0.0.0-127.0.7.255
(new YZhanIP('2001:4860:4801:0000:0000:0000:0000:af88'))->toString(); // 2001:4860:4801::af88
(new YZhanIP(['2001:4860:*::af88', '2001:4860:4801::af88/7']))->toString(); // 2001:4860::af88-2001:4860:ffff::af88,2000::-21ff:ffff:ffff:ffff:ffff:ffff:ffff:ffff
```

#### To Raw String

[](#to-raw-string)

#### 返回原始字符串

[](#返回原始字符串)

```
(new YZhanIP('2001:4860:4801:0000:0000:0000:0000:af88'))->toRaw(); // 2001:4860:4801:0000:0000:0000:0000:af88
(new YZhanIP(['127.0.0.*', '127.0.0.1/21']))->toRaw(); // 127.0.0.*,127.0.0.1/21
(new YZhanIP(['2001:4860:*::af88', '2001:4860:4801::af88/7']))->toRaw(); // 2001:4860:*::af88,2001:4860:4801::af88/7
```

### Filter 过滤

[](#filter-过滤)

#### Retain items in a set of IP / IP ranges that are included in another set of IP / IP ranges

[](#retain-items-in-a-set-of-ip--ip-ranges-that-are-included-in-another-set-of-ip--ip-ranges)

#### 保留一组 IP / IP 范围中被另一组 IP / IP 范围中包含的项

[](#保留一组-ip--ip-范围中被另一组-ip--ip-范围中包含的项)

```
(new YZhanIP(['127.0.0.1', '65.0.0.1', '2001:4860:4801::af88', '3001::af88', '127.0.0.*', '2001:4860:4801::af88-2001:4860:4801::afff']))->filter(['127.0.0.1/21', '2001:4860:4801::af88/7'])->toRaw(); // 127.0.0.1,2001:4860:4801::af88,127.0.0.*,2001:4860:4801::af88-2001:4860:4801::afff
```

### Tracer 溯源

[](#tracer-溯源)

```
use YZhanIP\Tool\IPTracer;
```

#### Check if the IP / IP range is Cloudflare node IP

[](#check-if-the-ip--ip-range-is-cloudflare-node-ip)

#### 检测 IP / IP 范围 是否是 Cloudflare 节点 IP

[](#检测-ip--ip-范围-是否是-cloudflare-节点-ip)

```
IPTracer::IsCloudflareNode('173.245.48.1'); // true
IPTracer::IsCloudflareNode('173.245.48.0/20'); // true
IPTracer::IsCloudflareNode('2400:cb00::1'); // true
IPTracer::IsCloudflareNode('2400:cb00::/32'); // true
```

#### Check if the IP / IP range is Googlebot IP

[](#check-if-the-ip--ip-range-is-googlebot-ip)

#### 检测 IP / IP 范围 是否是 Google 漫游器 IP

[](#检测-ip--ip-范围-是否是-google-漫游器-ip)

```
IPTracer::IsGoogleBot('66.249.64.97'); // true
IPTracer::IsGoogleBot('66.249.64.0/27'); // true
IPTracer::IsGoogleBot('2001:4860:4801:48::1'); // true
IPTracer::IsGoogleBot('2001:4860:4801:10::/64'); // true
```

#### Check if the IP / IP range is in the URL content

[](#check-if-the-ip--ip-range-is-in-the-url-content)

#### 检测 IP / IP 范围 是否在指定 URL 的内容中出现

[](#检测-ip--ip-范围-是否在指定-url-的内容中出现)

```
IPTracer::IsInUrl(['173.245.48.1', '2400:cb00::1', '2400:cb00::/32'], ['https://www.cloudflare.com/ips-v4', 'https://www.cloudflare.com/ips-v6']); // true
```

### Crawler 爬取

[](#crawler-爬取)

```
use YZhanIP\Tool\IPCrawler;
```

#### Extract IP / IP range array from URL

[](#extract-ip--ip-range-array-from-url)

#### 从 URL 中提取 IP / IP 范围为数组

[](#从-url-中提取-ip--ip-范围为数组)

```
$url = '{URL with IP and IP range inside}';
$ipCrawler = new IPCrawler($url, array( // The following are Default Config, no Modification no Statement
  'cacheDir' => sys_get_temp_dir(),
  'cacheKey' => 'yzhanip' . md5($url),
  'cacheMaxAge' => 86400, // Unit: s
  'timeOut' => 6,
));
// $ipCrawler = new IPCrawler($url); // use Default Config
$ipCrawler->get() // array('{IP}', '{IP Range}' ...)
```

#### Update Cache

[](#update-cache)

#### 更新缓存

[](#更新缓存)

```
$ipCrawler->update();
```

### Parser 解析

[](#parser-解析)

```
use YZhanIP\Tool\IPParser;
```

#### Get the type of IP / IP range

[](#get-the-type-of-ip--ip-range)

#### 检测 IP / IP 范围的类型

[](#检测-ip--ip-范围的类型)

```
IPParser::GetType('127.0.0.1'); // IPV4
IPParser::GetType('127.0.0.1/21'); // IPV4CIDR
IPParser::GetType('127.0.0.1-127.0.0.30'); // IPV4INTERVAL
IPParser::GetType('127.0.0.*'); // IPV4WILDCARD
IPParser::GetType('2001:4860:4801::af88'); // IPV6
IPParser::GetType('2001:4860:4801::af88/7'); // IPV6CIDR
IPParser::GetType('2001:4860:4801::af88-2001:4860:4801::afff'); // IPV6INTERVAL
IPParser::GetType('2001:4860:*::af88'); // IPV6WILDCARD
```

#### Check the type of IP / IP range

[](#check-the-type-of-ip--ip-range)

#### 判断 IP / IP 范围的类型

[](#判断-ip--ip-范围的类型)

```
IPParser::IsIPv4('127.0.0.1'); // true
IPParser::IsIPV4CIDR('127.0.0.1/21'); // true
IPParser::IsIPv4Interval('127.0.0.1-127.0.0.30'); // true
IPParser::IsIPv4Wildcard('127.0.0.*'); // true
IPParser::IsIPv6('2001:4860:4801::af88'); // true
IPParser::IsIPV6CIDR('2001:4860:4801::af88/7'); // true
IPParser::IsIPv6Interval('2001:4860:4801::af88-2001:4860:4801::afff'); // true
IPParser::IsIPv6Wildcard('2001:4860:*::af88'); // true
IPParser::IsIP('127.0.0.1'); // true
IPParser::IsIP('2001:4860:4801::af88'); // true
IPParser::IsIPCIDR('127.0.0.1/21'); // true
IPParser::IsIPCIDR('2001:4860:4801::af88/7'); // true
IPParser::IsIPInterval('127.0.0.1-127.0.0.30'); //  true
IPParser::IsIPInterval('2001:4860:4801::af88-2001:4860:4801::afff'); // true
IPParser::IsIPWildcard('127.0.0.*'); // true
IPParser::IsIPWildcard('2001:4860:*::af88'); // true
```

#### Get an IP / IP range array from HTML / TXT / JSON etc.

[](#get-an-ip--ip-range-array-from-html--txt--json-etc)

#### 从 HTML / TXT / JSON 等内容中提取 IP / IP 范围为数组

[](#从-html--txt--json-等内容中提取-ip--ip-范围为数组)

```
/** $content is mixed content of IPv4 IPv6 IPRange */
IPParser::MatchAllIPv4($content); // array('127.0.0.1')
IPParser::MatchAllIPv4CIDR($content); // array('127.0.0.1/21')
IPParser::MatchAllIPv4Interval($content); // array('127.0.0.1-127.0.0.30')
IPParser::MatchAllIPv4Wildcard($content); // array('127.0.0.*')
IPParser::MatchAllIPv6($content); // array('2001:4860:4801::af88')
IPParser::MatchAllIPv6CIDR($content); // array('2001:4860:4801::af88/7')
IPParser::MatchAllIPv6Interval($content); // array('2001:4860:4801::af88-2001:4860:4801::afff')
IPParser::MatchAllIPv6Wildcard($content); // array('2001:4860:*::af88')
IPParser::MatchAllIP($content); // array('127.0.0.1', 2001:4860:4801::af88')
IPParser::MatchAllIPCIDR($content); // array('127.0.0.1/21', '2001:4860:4801::af88/7')
IPParser::MatchAllIPInterval($content); // array('127.0.0.1-127.0.0.30', '2001:4860:4801::af88-2001:4860:4801::afff')
IPParser::MatchAllIPWildcard($content); // array('127.0.0.*', '2001:4860:*::af88')
IPParser::MatchAll($content); // array('127.0.0.1', 2001:4860:4801::af88', '127.0.0.1/21', '2001:4860:4801::af88/7', '127.0.0.1-127.0.0.30', '2001:4860:4801::af88-2001:4860:4801::afff', '127.0.0.*', '2001:4860:*::af88')
```

### Converter 转换

[](#converter-转换)

```
use YZhanIP\Tool\IPConverter;
```

#### Convert IP to binary string

[](#convert-ip-to-binary-string)

#### IP 转换为二进制字符串

[](#ip-转换为二进制字符串)

```
IPConverter::IP2Bit('127.0.0.1'); // 01111111000000000000000000000001
IPConverter::IP2Bit('2001:4860:4801::af88'); // 00100000000000010100100001100000010010000000000100000000000000000000000000000000000000000000000000000000000000001010111110001000
```

#### Convert binary string to IP

[](#convert-binary-string-to-ip)

#### 二进制字符串转换为 IP

[](#二进制字符串转换为-ip)

```
IPConverter::Bit2IP('01111111000000000000000000000001'); // 127.0.0.1
IPConverter::Bit2IP('00100000000000010100100001100000010010000000000100000000000000000000000000000000000000000000000000000000000000001010111110001000'); // 2001:4860:4801::af88
```

#### Convert CIDR to IP range

[](#convert-cidr-to-ip-range)

#### CIDR 转 IP 范围

[](#cidr-转-ip-范围)

```
$ipv4Range = IPConverter::IPCIDR2IPRange('127.0.0.1/24');
$ipv4Range->getFirst(); // 127.0.0.0
$ipv4Range->getLast(); // 127.0.7.255
$ipv6Range = IPConverter::IPCIDR2IPRange('2001:4860:4801::af88/7');
$ipv6Range->getFirst(); // 2000::
$ipv6Range->getLast(); // 21ff:ffff:ffff:ffff:ffff:ffff:ffff:ffff
```

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity30

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 90.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~11 days

Total

2

Last Release

1334d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/186219fca45bab5c5266d7c1f22c79c217f21ba7ada3142795a8ae69f95be0f6?d=identicon)[mantoufan](/maintainers/mantoufan)

---

Top Contributors

[![mantoufan](https://avatars.githubusercontent.com/u/4961543?v=4)](https://github.com/mantoufan "mantoufan (10 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (1 commits)")

---

Tags

cloudflaregooglebotipv4ipv6ipv6parsercrawlerIPipv4cidrwildcardtraceriprangeConveter

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/mantoufan-yzhanip/health.svg)

```
[![Health](https://phpackages.com/badges/mantoufan-yzhanip/health.svg)](https://phpackages.com/packages/mantoufan-yzhanip)
```

###  Alternatives

[s1lentium/iptools

PHP Library for manipulating network addresses (IPv4 and IPv6)

2446.2M24](/packages/s1lentium-iptools)[cidram/aggregator

A stand-alone class implementation of the IPv4+IPv6 IP+CIDR aggregator from CIDRAM.

2624.1k](/packages/cidram-aggregator)[crwlr/robots-txt

Robots Exclusion Standard/Protocol Parser for Web Crawling/Scraping

1125.3k1](/packages/crwlr-robots-txt)[laurentvw/scrapher

A web scraper for PHP to easily extract data from web pages

192.5k1](/packages/laurentvw-scrapher)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
