@@ -12,7 +12,7 @@ class Database
1212 *
1313 * @var string
1414 */
15- public const VERSION = '9.7.3 ' ;
15+ public const VERSION = '9.8.0 ' ;
1616
1717 /**
1818 * Unsupported field message.
@@ -224,6 +224,27 @@ class Database
224224 */
225225 public const AS = 25 ;
226226
227+ /**
228+ * AS domain.
229+ *
230+ * @var int
231+ */
232+ public const AS_DOMAIN = 26 ;
233+
234+ /**
235+ * AS usage type.
236+ *
237+ * @var int
238+ */
239+ public const AS_USAGE_TYPE = 27 ;
240+
241+ /**
242+ * AS CIDR.
243+ *
244+ * @var int
245+ */
246+ public const AS_CIDR = 28 ;
247+
227248 /**
228249 * Country name and code.
229250 *
@@ -440,6 +461,9 @@ class Database
440461 self ::DISTRICT => [0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 92 ],
441462 self ::ASN => [0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 96 ],
442463 self ::AS => [0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 100 ],
464+ self ::AS_DOMAIN => [0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 104 ],
465+ self ::AS_USAGE_TYPE => [0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 108 ],
466+ self ::AS_CIDR => [0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 112 ],
443467 ];
444468
445469 /**
@@ -473,6 +497,9 @@ class Database
473497 self ::DISTRICT => 'district ' ,
474498 self ::ASN => 'asn ' ,
475499 self ::AS => 'as ' ,
500+ self ::AS_DOMAIN => 'asDomain ' ,
501+ self ::AS_USAGE_TYPE => 'asUsageType ' ,
502+ self ::AS_CIDR => 'asCidr ' ,
476503 self ::IP_ADDRESS => 'ipAddress ' ,
477504 self ::IP_VERSION => 'ipVersion ' ,
478505 self ::IP_NUMBER => 'ipNumber ' ,
@@ -1039,6 +1066,9 @@ public function lookup($ip, $fields = null, $asNamed = true)
10391066 $ ifields [] = self ::DISTRICT ;
10401067 $ ifields [] = self ::ASN ;
10411068 $ ifields [] = self ::AS ;
1069+ $ ifields [] = self ::AS_DOMAIN ;
1070+ $ ifields [] = self ::AS_USAGE_TYPE ;
1071+ $ ifields [] = self ::AS_CIDR ;
10421072
10431073 $ ifields [] = self ::COUNTRY ;
10441074 $ ifields [] = self ::COORDINATES ;
@@ -1085,6 +1115,9 @@ public function lookup($ip, $fields = null, $asNamed = true)
10851115 self ::DISTRICT => false ,
10861116 self ::ASN => false ,
10871117 self ::AS => false ,
1118+ self ::AS_DOMAIN => false ,
1119+ self ::AS_USAGE_TYPE => false ,
1120+ self ::AS_CIDR => false ,
10881121 self ::COUNTRY => false ,
10891122 self ::COORDINATES => false ,
10901123 self ::IDD_AREA => false ,
@@ -1324,6 +1357,27 @@ public function lookup($ip, $fields = null, $asNamed = true)
13241357 }
13251358 break ;
13261359
1360+ case self ::AS_DOMAIN :
1361+ if (!$ done [self ::AS_DOMAIN ]) {
1362+ $ results [self ::AS_DOMAIN ] = $ this ->readAsDomain ($ pointer );
1363+ $ done [self ::AS_DOMAIN ] = true ;
1364+ }
1365+ break ;
1366+
1367+ case self ::AS_USAGE_TYPE :
1368+ if (!$ done [self ::AS_USAGE_TYPE ]) {
1369+ $ results [self ::AS_USAGE_TYPE ] = $ this ->readAsUsageType ($ pointer );
1370+ $ done [self ::AS_USAGE_TYPE ] = true ;
1371+ }
1372+ break ;
1373+
1374+ case self ::AS_CIDR :
1375+ if (!$ done [self ::AS_CIDR ]) {
1376+ $ results [self ::AS_CIDR ] = $ this ->readAsCidr ($ pointer );
1377+ $ done [self ::AS_CIDR ] = true ;
1378+ }
1379+ break ;
1380+
13271381 case self ::IP_ADDRESS :
13281382 if (!$ done [self ::IP_ADDRESS ]) {
13291383 $ results [self ::IP_ADDRESS ] = $ ip ;
@@ -1462,9 +1516,9 @@ private function getMemoryLimit()
14621516 // Deal with shorthand bytes
14631517 switch (strtoupper (substr ($ memoryLimit , -1 ))) {
14641518 case 'G ' : $ value *= 1024 ;
1465- // no break
1519+ // no break
14661520 case 'M ' : $ value *= 1024 ;
1467- // no break
1521+ // no break
14681522 case 'K ' : $ value *= 1024 ;
14691523 }
14701524 }
@@ -2157,6 +2211,66 @@ private function readAs($pointer)
21572211 return $ this ->readString ($ this ->columns [self ::AS ][$ this ->type ]);
21582212 }
21592213
2214+ /**
2215+ * High level function to fetch the AS domain.
2216+ *
2217+ * @param int $pointer Position to read from, if false, return self::INVALID_IP_ADDRESS
2218+ *
2219+ * @return string
2220+ */
2221+ private function readAsDomain ($ pointer )
2222+ {
2223+ if ($ pointer === false ) {
2224+ return self ::INVALID_IP_ADDRESS ;
2225+ }
2226+
2227+ if ($ this ->columns [self ::AS_DOMAIN ][$ this ->type ] === 0 ) {
2228+ return self ::FIELD_NOT_SUPPORTED ;
2229+ }
2230+
2231+ return $ this ->readString ($ this ->columns [self ::AS_DOMAIN ][$ this ->type ]);
2232+ }
2233+
2234+ /**
2235+ * High level function to fetch the AS usage type.
2236+ *
2237+ * @param int $pointer Position to read from, if false, return self::INVALID_IP_ADDRESS
2238+ *
2239+ * @return string
2240+ */
2241+ private function readAsUsageType ($ pointer )
2242+ {
2243+ if ($ pointer === false ) {
2244+ return self ::INVALID_IP_ADDRESS ;
2245+ }
2246+
2247+ if ($ this ->columns [self ::AS_USAGE_TYPE ][$ this ->type ] === 0 ) {
2248+ return self ::FIELD_NOT_SUPPORTED ;
2249+ }
2250+
2251+ return $ this ->readString ($ this ->columns [self ::AS_USAGE_TYPE ][$ this ->type ]);
2252+ }
2253+
2254+ /**
2255+ * High level function to fetch the AS CIDR.
2256+ *
2257+ * @param int $pointer Position to read from, if false, return self::INVALID_IP_ADDRESS
2258+ *
2259+ * @return string
2260+ */
2261+ private function readAsCidr ($ pointer )
2262+ {
2263+ if ($ pointer === false ) {
2264+ return self ::INVALID_IP_ADDRESS ;
2265+ }
2266+
2267+ if ($ this ->columns [self ::AS_CIDR ][$ this ->type ] === 0 ) {
2268+ return self ::FIELD_NOT_SUPPORTED ;
2269+ }
2270+
2271+ return $ this ->readString ($ this ->columns [self ::AS_CIDR ][$ this ->type ]);
2272+ }
2273+
21602274 /**
21612275 * Get the boundaries for an IP address.
21622276 *
0 commit comments