GC_Http::is_ip_address()

最后更新于:2021-12-01 11:13:57

GC_( string$maybe_ip)

Determines if a specified string represents an IP address or not.

参数

$maybe_ip

(string) (Required) A suspected IP address.

响应

(int|false) Upon success, ‘4’ or ‘6’ to represent a IPv4 or IPv6 address, false upon failure

源文件

文件: gc-includes/class-http.php

	public static function is_ip_address( $maybe_ip ) {
		if ( preg_match( '/^d{1,3}.d{1,3}.d{1,3}.d{1,3}$/', $maybe_ip ) ) {
			return 4;
		}

		if ( false !== strpos( $maybe_ip, ':' ) && preg_match( '/^(((?=.*(::))(?!.*3.+3))3?|([dA-F]{1,4}(3|:b|$)|2))(?4){5}((?4){2}|(((2[0-4]|1d|[1-9])?d|25[0-5]).?b){4})$/i', trim( $maybe_ip, ' []' ) ) ) {
			return 6;
		}

		return false;
	}