PHPackages                             mileschou/twnicip - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. mileschou/twnicip

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

mileschou/twnicip
=================

Twnic IP

v1.0.6(1y ago)131.9kMITPHPPHP ^8.0

Since Aug 13Pushed 1y ago1 watchersCompare

[ Source](https://github.com/MilesChou/twnicip)[ Packagist](https://packagist.org/packages/mileschou/twnicip)[ Fund](https://www.paypal.me/mileschou)[ RSS](/packages/mileschou-twnicip/feed)WikiDiscussions 1.x Synced 2d ago

READMEChangelog (10)Dependencies (8)Versions (21)Used By (0)

Twnic IP
========

[](#twnic-ip)

[![tests](https://github.com/MilesChou/twnicip/workflows/tests/badge.svg)](https://github.com/MilesChou/twnicip/workflows/tests/badge.svg)[![codecov](https://camo.githubusercontent.com/cc2872ba27ccc828a543f3688def4a0498bbae205f2b23fd58dee4d549d9a5c2/68747470733a2f2f636f6465636f762e696f2f67682f4d696c657343686f752f74776e696369702f6272616e63682f6d61737465722f67726170682f62616467652e7376673f746f6b656e3d4f507a59516a34326251)](https://codecov.io/gh/MilesChou/twnicip)[![Codacy Badge](https://camo.githubusercontent.com/8c83d9e15fff4e816084ec48107585a4e1d52598b88413b552281bba837e9d71/68747470733a2f2f6170702e636f646163792e636f6d2f70726f6a6563742f62616467652f47726164652f3466383265636237646431323437386362613962353163386262323664373465)](https://www.codacy.com/gh/MilesChou/twnicip/dashboard)[![Latest Stable Version](https://camo.githubusercontent.com/f8ed7590c45b12682fcf3906abf5093278303d7dda98deb5470e9013aaa596af/68747470733a2f2f706f7365722e707567782e6f72672f4d696c657343686f752f74776e696369702f762f737461626c65)](https://packagist.org/packages/MilesChou/twnicip)[![Total Downloads](https://camo.githubusercontent.com/b52a8bdec119c002079b014f77241903b46555164297415ff192d8722ea66ddd/68747470733a2f2f706f7365722e707567782e6f72672f4d696c657343686f752f74776e696369702f642f746f74616c2e737667)](https://packagist.org/packages/MilesChou/twnicip)[![License](https://camo.githubusercontent.com/348d2515a537d5ce703c5b6156b02bcc4cb571c848812dd7164bf481a101ff33/68747470733a2f2f706f7365722e707567782e6f72672f4d696c657343686f752f74776e696369702f6c6963656e7365)](https://packagist.org/packages/MilesChou/twnicip)

檢查是否為台灣 IP 的小工具。

台灣 IP 沒想像中多，這個工具是直接把找到的資料轉成 PHP 原生變數型態的「[資料庫](/src/Database.php)」，再使用另一個 [Facade](/src/TwnicIp.php) 做搜尋。

原始 Database 是不能修改的，只能靠原 repo 更新，而 Facade 層則是可以動態標記 IP 是否為台灣 IP。

Version
-------

[](#version)

- 0.x 版支援 PHP 7.1 ~ 8.0
- 1.x 版支援 PHP 8.0+

Installation
------------

[](#installation)

透過 Composer 即可安裝：

```
composer require mileschou/twnicip
```

Usage
-----

[](#usage)

這是主要驗證 IP 來源的 class，使用下面三個方法來確認是否是台灣 IP：

```
$twnicIp = new TwnicIp();

$twnicIp->isTaiwan('202.39.128.1'); // isTaiwanByIp() 的別名
$twnicIp->isTaiwanByIp('202.39.128.1');
$twnicIp->isTaiwanByLong(3391586305); // 轉成 IP 即 202.39.128.1
```

如果有新加入的 IP，但原始 repo 沒有更新時，可以自行新增：

```
$twnicIp->includeRange('127.0.0.1', '127.0.0.1');

$twnicIp->isTaiwan('127.0.0.1'); // return true
```

同理，如果某個區段的 IP 需要被排除時，也可以自行處理：

```
$twnicIp->excludeRange('127.0.0.1', '127.0.0.1');

$twnicIp->isTaiwan('127.0.0.1'); // return false
```

私有網域狹義來說，並不屬於台灣的 IP。而實務上，機器在台灣，某種程度也是算台灣的 IP 啦！

如果想把私有網域當作台灣 IP 的話，可以額外呼叫下面這個方法：

```
$twnicIp->includePrivateIp();
```

裡面其實只是呼叫 `includeRange()` 把私有 IP 的 range 加入。

References
----------

[](#references)

- [Twnic IP 列表](https://www.twnic.tw/download/IP/main_f3.htm) - 但此文件看起來已過時，因此改採用其他資料庫
- [IP2LOCATION Lite](https://lite.ip2location.com/) - 免費且完整的資料庫，目前是使用這個

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance40

Moderate activity, may be stable

Popularity23

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~61 days

Recently: every ~85 days

Total

21

Last Release

510d ago

Major Versions

v0.3.7 → v1.0.02023-09-27

PHP version history (3 changes)v0.0.1PHP ^7.1 | ^8

v0.2.0PHP ^7.1 | ^8.0

v1.0.0PHP ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/20872dcc4b888075f03819d5470db8198ffcc5f9edb791aba5f007e34355a6c9?d=identicon)[MilesChou](/maintainers/MilesChou)

---

Top Contributors

[![MilesChou](https://avatars.githubusercontent.com/u/1258752?v=4)](https://github.com/MilesChou "MilesChou (48 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/mileschou-twnicip/health.svg)

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

###  Alternatives

[phalcon/zephir

Zephir is a compiled high level language aimed to the creation of C-extensions for PHP

3.4k414.1k18](/packages/phalcon-zephir)[code-tool/jaeger-client-php

35520.8k9](/packages/code-tool-jaeger-client-php)[rafaelfragoso/haversini-formula

This PHP class can replace the Google Distance Matrix to calculate the distance between two points using latitude and longitude. It will prevent you to do massive requests to Google servers and enhance your service performance.

45212.0k](/packages/rafaelfragoso-haversini-formula)

PHPackages © 2026

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