Sunday, November 17, 2024
Google search engine
HomeLanguagesPHP | inet_ntop() Function

PHP | inet_ntop() Function

The inet_ntop() function is an inbuilt function in PHP which converts a 32bit IPv4 or 128bit IPv6 address into a readable format.

Syntax:

string inet_ntop( string $ip_address )

Parameter: This function accepts one parameter as mentioned above and described below:

  • $ip_address: It is required parameter. It specifies a 32bit IPv4 or 128bit IPv6 address.

Return Value: This function returns a string formatted human readable address on success or FALSE on failure.

Note: This function is available on PHP 5.1.0 and newer version.

Below programs illustrate the inet_ntop() function in PHP:

Program 1:




<?php
  
// Store the address into variable
$addr = chr(127) . chr(0) . chr(1) . chr(1);
  
// Use inet_ntop() function to convert
// internet address to a human readable
// representation
$exp = inet_ntop($addr);
  
// Display result
echo $exp;
  
?>


Output:

127.0.1.1

Program 2: This program uses a string of size 4 of ascii characters directly in the parameter.




<?php
  
// Use inet_ntop() function to convert
// internet address to a human readable
// representation
echo inet_ntop("[][]") . "<br>";
echo inet_ntop("4509") . "<br>";
echo inet_ntop("*^b@") . "<br>";
echo inet_ntop("hqp0") . "<br>";
echo inet_ntop("2c#!");
  
?>


Output:

91.93.91.93
52.53.48.57
42.94.98.64
104.113.112.48
50.99.35.33

Reference: https://www.php.net/manual/en/function.inet-ntop.php

Dominic Rubhabha-Wardslaus
Dominic Rubhabha-Wardslaushttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Recent Comments