Converts any given IPv4/v6 address to a string representation of it's 32/128bit integer
which may be used for comparison

@param string $address
@return string|bool
186235
public function getIpNumberFromAddress($address)
    {
        // Unrecognised addresses cause PHP warnings, silence the warning and return a bool instead
        $pton = @inet_pton($address);
        if (!$pton) {
            return false;
        }

        $number = '';
        foreach (unpack('C*', $pton) as $byte) {
            $number .= str_pad(decbin($byte), 8, '0', STR_PAD_LEFT);
        }

        return base_convert(ltrim($number, '0'), 2, 10);
    }
324638
protected function unformatAddress($address, &$port)
    {
        // [::1]:2 => ::1 2
        // test:2 => test 2
        // ::1 => ::1
        // test => test

        $colon = strrpos($address, ':');

        // there is a colon and this is the only colon or there's a closing IPv6 bracket right before it
        if ($colon !== false && (strpos($address, ':') === $colon || strpos($address, ']') === ($colon - 1))) {
            $port = (int)substr($address, $colon + 1);
            $address = substr($address, 0, $colon);

            // remove IPv6 square brackets
            if (substr($address, 0, 1) === '[') {
                $address = substr($address, 1, -1);
            }
        }
        return $address;
    }
1052412
protected function convertIPv4Address($ipv4Address) {
        $longIP = ip2long($ipv4Address);

        if (!is_int($longIP)) {
            throw new RuntimeException(sprintf(
                'Unable to convert IP address "%s"',
                $ipv4Address
            ));
        }

        return $longIP;
    }
143505
public static function normalizeIPv6($address) {
		$normalizedAddress = '';
		$stageOneAddress = '';

			// according to RFC lowercase-representation is recommended
		$address = strtolower($address);

			// normalized representation has 39 characters (0000:0000:0000:0000:0000:0000:0000:0000)
		if (strlen($address) == 39) {
				// already in full expanded form
			return $address;
		}

		$chunks = explode('::', $address); // Count 2 if if address has hidden zero blocks
		if (count($chunks) == 2) {
			$chunksLeft = explode(':', $chunks[0]);
			$chunksRight = explode(':', $chunks[1]);
			$left = count($chunksLeft);
			$right = count($chunksRight);

				// Special case: leading zero-only blocks count to 1, should be 0
			if ($left == 1 && strlen($chunksLeft[0]) == 0) {
				$left = 0;
			}

			$hiddenBlocks = 8 - ($left + $right);
			$hiddenPart = '';
			$h = 0;
			while ($h < $hiddenBlocks) {
				$hiddenPart .= '0000:';
				$h++;
			}

			if ($left == 0) {
				$stageOneAddress = $hiddenPart . $chunks[1];
			} else {
				$stageOneAddress = $chunks[0] . ':' . $hiddenPart . $chunks[1];
			}
		} else {
			$stageOneAddress = $address;
		}

			// normalize the blocks:
		$blocks = explode(':', $stageOneAddress);
		$divCounter = 0;
		foreach ($blocks as $block) {
			$tmpBlock = '';
			$i = 0;
			$hiddenZeros = 4 - strlen($block);
			while ($i < $hiddenZeros) {
				$tmpBlock .= '0';
				$i++;
			}
			$normalizedAddress .= $tmpBlock . $block;
			if ($divCounter < 7) {
				$normalizedAddress .= ':';
				$divCounter++;
			}
		}
		return $normalizedAddress;
	}
1074561
public static function parse(string $address)
    {
        static $regex = null;
        if (null === $regex) {
            $grammar = Grammar::getInstance();

            $addrSpec = $grammar->getDefinition('addr-spec');
            $cfws = $grammar->getDefinition('CFWS');
            $phrase = $grammar->getDefinition('phrase');

            $regex = '/(?<address>'.$addrSpec.')|(?:(?<name>'.$phrase.')(?:'.$cfws.'?)<(?<addressalt>'.$addrSpec.')>(?:'.$cfws.'?))/';
        }

        if (! \preg_match($regex, $address, $match)) {
            return null;
        }

        $addr = isset($match['addressalt']) ? $match['addressalt'] : $match['address'];

        $name = $match['name'] ?? '';
        $name = \trim($name, " \t\n\r\0\x0B\"");

        return [
            'address' => $addr,
            'personal' => $name,
        ];
    }
119705
public function deleteAddress(Address $address)
    {
        if ($this !== $address->addressable()->first())
            return false;

        return $address->delete();
    }
1111202
private function lookupIP($address)
    {
        // Create the responses storage array
        $responses = [];

        // Query every server in the IP list
        foreach ($this->servers->ip as $server) {
            // Check if we haven't queried this server yet
            if (array_key_exists($server, $responses)) {
                continue;
            }

            // Query the server
            $responses[$server] = $this->query($address, $server);
        }

        // Create a result object
        $result = new Result();

        // Set target
        $result->target = $address;

        // Set the type
        $result->type = 'ip';

        // Set response count
        $result->count = count($responses);

        // Set responses
        $result->responses = array_reverse($responses);

        // Return the Result object
        return $result;
    }
481533
public static function geocode($address)
	{
		if(!is_string($address)) return array();
		
		$query = new Dm_Geocoder_Query($address);
		$finded = Dm_Geocoder_GISCSV_Finder::find($query);
		
		return $finded;
		
	}
1150596
public static function addressFromBytes(array $bytes)
    {
        $result = null;
        if ($result === null) {
            $result = Address\IPv4::fromBytes($bytes);
        }
        if ($result === null) {
            $result = Address\IPv6::fromBytes($bytes);
        }

        return $result;
    }
461953
@Nullable
    static byte[] ipv6ToIpv4Address(Inet6Address address) {
        final byte[] addr = address.getAddress();
        assert addr.length == 16
                : "the length of " + address.getClass().getSimpleName() + ": " + addr.length;
        // The first 10 bytes should be 0.
        for (int i = 0; i < 10; i++) {
            if (addr[i] != 0x00) {
                return null;
            }
        }

        if (addr[10] == 0x00 && addr[11] == 0x00) {
            if (addr[12] == 0x00 && addr[13] == 0x00 && addr[14] == 0x00 && addr[15] == 0x01) {
                return localhost;
            }
            return new byte[] { addr[12], addr[13], addr[14], addr[15] };
        }

        if (addr[10] == (byte) 0xFF && addr[11] == (byte) 0xFF) {
            return new byte[] { addr[12], addr[13], addr[14], addr[15] };
        }

        return null;
    }
35838
private function justAddress($address)
    {
        if (($pos = strpos($address, '<')) === false) {
            return $address;
        }

        $n = strlen($address);
        if ($address[$n - 1] == '>') {
            $address = substr($address, $pos + 1, -1);
        }

        return $address;
    }
759106
public static function IPv4toInteger($ip)
    {
        $ips = explode('.', $ip);
        $integer = 0;
        for ($i = 0; $i < 4; $i++)
        {
            $ips[$i] = intval($ips[$i] % 256);
            $ips[$i] = pow(256, 3 - $i) * intval($ips[$i]);
            $integer += $ips[$i];
        }
        return $integer;
    }
190552
private function isAddressValid(string $address): bool
    {
        $position = \strrpos($address, ':');
        if ($position === false) {
            return ($address[0] ?? '') === "\0"; // udg socket address.
        }

        $ip = \trim(\substr($address, 0, $position), '[]');
        $port = (int) \substr($address, $position + 1);

        return \inet_pton($ip) !== false && $port > 0 && $port < 65536;
    }
84587
static public function ConvertIPv4CIDRToDecimal($ipAndCidr)
    {

        list($ip, $subnetMask) = explode("/", $ipAndCidr);

        $ip = static::ConvertIPv4ToDecimal($ip);

        $subnetMask = static::ConvertIPv4CIDRToMask($subnetMask);

        $subnetMask = static::ConvertIPv4ToDecimal($subnetMask);

        return compact('ip', 'subnetMask');

    }
1024481
protected function isOtherServerProcessRunning($address)
    {
        if (file_exists(sys_get_temp_dir().'/'.strtr($address, '.:', '--').'.pid')) {
            return true;
        }

        list($hostname, $port) = explode(':', $address);

        if (false !== $fp = @fsockopen($hostname, $port, $errno, $errstr, 5)) {
            fclose($fp);

            return true;
        }

        return false;
    }
834948
@VisibleForTesting
  static String reverse(InetAddress address) {
    byte[] bytes = address.getAddress();
    if (bytes.length == 4) return reverseIpv4(bytes);
    else return reverseIpv6(bytes);
  }
226018
public function retrieve($address) {
		/** @var \Geo\Model\Entity\GeocodedAddress $entity */
		$entity = $this->find()->where(['address' => $address])->first();
		if ($entity) {
			return $entity;
		}

		$result = $this->_execute($address);
		$address = $this->newEntity([
			'address' => $address
		]);
		if ($result) {
			$address->lat = $result->getLatitude();
			$address->lng = $result->getLongitude();
			$address->country = $result->getCountry()->getCode();

			$formatter = new StringFormatter();
			$address->formatted_address = $formatter->format($result, '%S %n, %z %L');
			$address->data = $result;
		}

		return $this->save($address);
	}