Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
suppermoment committed Jul 2, 2020
1 parent 2a76c0a commit 320ea7c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 19 deletions.
11 changes: 5 additions & 6 deletions README-en.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ $ composer require tim168/ip

use Tim168\Ip\Ip;

$ip = new Ip('zh-CN'); //Support the following languages
## Supported language formats
| character| describe |
| :------------ | :------------ |
Expand All @@ -35,7 +34,7 @@ $ composer require tim168/ip
| zh-CN | chinese |
| ru | russian |
## Get Ip location information
$res = $ip->get('json','116.234.222.36')
$res = Ip::getIp('json','116.234.222.36')

## Example
{
Expand All @@ -55,7 +54,7 @@ $ composer require tim168/ip
"query": "116.234.222.36"
}
## Get Xml Format
$res = $ip->get('xml','116.234.222.36')
$res = Ip::getIp('xml','116.234.222.36')
## Example
<?xml version="1.0" encoding="UTF-8"?>
<query>
Expand All @@ -75,7 +74,7 @@ $ composer require tim168/ip
<query>116.234.222.36</query>
</query>
## GET Csv Format
$res = $ip->get('csv','116.234.222.36')
$res = Ip::getIp('csv','116.234.222.36')
## Example
success,China,CN,SH,Shanghai,Shanghai,,31.0449,121.4012,Asia/Shanghai,China Telecom (Group),Chinanet SH,AS4812 China
Telecom (Group),116.234.222.36
Expand All @@ -86,13 +85,13 @@ $ composer require tim168/ip
Telecom (Group)";s:3:"org";s:11:"Chinanet SH";s:2:"as";s:28:"AS4812 China Telecom
(Group)";s:5:"query";s:14:"116.234.222.36";}
## IpV4 to IpV6
$res = $ip->IpV4toV6('116.234.222.36')
$res = Ip::IpV4toV6('116.234.222.36')

## Example
0000:0000:0000:0000:0000:ffff:74ea:de24

## IpV6 to IpV4
$res = $ip->IpV6toV4('0000:0000:0000:0000:0000:ffff:74ea:de24')
$res = Ip::IpV6toV4('0000:0000:0000:0000:0000:ffff:74ea:de24')

## Example
116.234.222.36
Expand Down
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ $ composer require tim168/ip

use Tim168\Ip\Ip;

$ip = new Ip('zh-CN'); //支持以下语言
## 支持的语言格式
| 字符集| 描述 |
| :------------ | :------------ |
Expand All @@ -36,7 +35,7 @@ $ composer require tim168/ip
| zh-CN | 中文 |
| ru | 俄语 |
## 获取Ip定位信息
$res = $ip->get('json','116.234.222.36')
$res = Ip::getIp('json','116.234.222.36')

## 示例
{
Expand All @@ -56,7 +55,7 @@ $ composer require tim168/ip
"query": "116.234.222.36" //ip
}
## 获取XML格式
$res = $ip->get('xml','116.234.222.36')
$res = Ip::getIp('xml','116.234.222.36')
## 示例
<?xml version="1.0" encoding="UTF-8"?>
<query>
Expand All @@ -76,24 +75,24 @@ $ composer require tim168/ip
<query>116.234.222.36</query>
</query>
## 获取CSV格式
$res = $ip->get('csv','116.234.222.36')
$res = Ip::getIp('csv','116.234.222.36')
## 示例
success,中国,CN,SH,上海,上海,,31.0449,121.4012,Asia/Shanghai,China Telecom (Group),Chinanet SH,AS4812 China Telecom
(Group),116.234.222.36
## 获取序列化格式
$res = $ip->get('php','116.234.222.36')
$res = Ip::getIp('php','116.234.222.36')
## 示例
a:14:{s:6:"status";s:7:"success";s:7:"country";s:6:"中国";s:11:"countryCode";s:2:"CN";s:6:"region";s:2:"SH";s:10:"regionName";s:6:"上海";s:4:"city";s:6:"上海";s:3:"zip";s:0:"";s:3:"lat";d:31.0449;s:3:"lon";d:121.4012;s:8:"timezone";s:13:"Asia/Shanghai";s:3:"isp";s:21:"China
Telecom (Group)";s:3:"org";s:11:"Chinanet SH";s:2:"as";s:28:"AS4812 China Telecom
(Group)";s:5:"query";s:14:"116.234.222.36";}
## IpV4转换成IpV6
$res = $ip->IpV4toV6('116.234.222.36')
$res = Ip::IpV4toV6('116.234.222.36')

## 示例
0000:0000:0000:0000:0000:ffff:74ea:de24

## IpV6转换成IpV4
$res = $ip->IpV6toV4('0000:0000:0000:0000:0000:ffff:74ea:de24')
$res = Ip::IpV6toV4('0000:0000:0000:0000:0000:ffff:74ea:de24')

## 示例
116.234.222.36
Expand Down
12 changes: 6 additions & 6 deletions src/Ip.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public static function checkIp($ip)
* @param $ip
* @throws InvalidArgumentException
*/
public function checkIpV4($ip)
public static function checkIpV4($ip)
{
if (!empty($ip)) {
if (!filter_var($ip, \FILTER_VALIDATE_IP, \FILTER_FLAG_IPV4)) {
Expand All @@ -88,7 +88,7 @@ public function checkIpV4($ip)
* @param $ip
* @throws InvalidArgumentException
*/
public function checkIpV6($ip)
public static function checkIpV6($ip)
{
if (!empty($ip)) {
if (!filter_var($ip, \FILTER_VALIDATE_IP, \FILTER_FLAG_IPV6)) {
Expand All @@ -102,9 +102,9 @@ public function checkIpV6($ip)
* @return string
* @throws InvalidArgumentException
*/
public function IpV4toV6($ip)
public static function IpV4toV6($ip)
{
$this->checkIpV4($ip);
self::checkIpV4($ip);
$set = '0000:0000:0000:0000:0000:ffff:';
$arr = explode('.', $ip);
$new = [];
Expand All @@ -124,9 +124,9 @@ public function IpV4toV6($ip)
* @return string
* @throws InvalidArgumentException
*/
public function IpV6toV4($ip)
public static function IpV6toV4($ip)
{
$this->checkIpV6($ip);
self::checkIpV6($ip);
$str = mb_substr($ip, 30, 38);
$arr = explode(':', $str);
$Ip1 = base_convert(mb_substr($arr[0], 0, 2), 16, 10);
Expand Down

0 comments on commit 320ea7c

Please sign in to comment.