Check port is open and not open using PHP

A port is used to recognize a specific service which is being executed in a computer. To recognize a port and to send packets, 16 bit numbers known as port numbers are used. A port number along with IP address serves as a destination for packets to be sent.

You can check port number open or not using simple php code


<?php
$host_connection = 'example.com'; // domain name
$ports_number = array(21, 25, 80, 81, 110,143, 443, 3306); //checking port number

foreach ($ports_number as $port)
{
$connection_check = @fsockopen($host_connection, $port);

if (is_resource($connection_check))
{
echo '<h5>' . $host_connection . ':' . $port . ' ' . '(' . getservbyport($port, 'tcp') . ') is open now.</h5>' . "\n";

fclose($connection_check);
}

else
{
echo '<h5>' . $host_connection . ':' . $port . ' is not open now.</h5>' . "\n";
}
}
?>

 


	 20, 21:  For FTP (File transfer protocol)
	 22: For SSH (Secure Shell)
	 23: For remote login (Telnet)
	 25: For SMTP (Simple mail transfer protocol)
	 53: For DNS (Domain Name System)
	 80: For World Wide Web
	 110: For POP3 (Post office protocol)
	 143: For IMAP (Internet Message Access Protocol)
	 194: For IRC (Internet relay chat)
	 443: For HTTPS (HTTP secure)
	 532: For Usenet newsgroups
     3306: MYSQL database system

For any query please leave a comment.

About these ads

About shafiqul
I am shafiq, i have passed B.Sc. in Computer Science and Engineering. 2010 from Rajshahi University of Engineering & Technology, Rajshahi. CGPA: 3.30 out of 4.00.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Resource

Web Development Resource

skrwebdesigner

Designer Tutorial

php tutorial

Code and examples of php,javascript,jquerymobiles,yii,codeigniter

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: