代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
PHP
】
检查端口
作者:
Dezai.CN
/ 发布于
2011/6/11
/
557
<div><span style="color: rgb(0,0,0); font-weight: bold"><?php</span> <span style="font-style: italic; color: rgb(128,128,128)">/*First, a variable must be used to store socket_create(). This will tell PHP the protocols and different settings that will be used to connect. For more information on this function, I would advise that you look at the PHP manual. I really didn't get too into this function, I just used some trial and error to find out what would work best. For those who do not know, the @ in front of the function prevents errors that might occur from showing. If you are having trouble with this script, it is suggested that you take the @ out.*/</span> <span style="font-style: italic; color: rgb(128,128,128)">//PC: $sock = @socket_create (<domain>, <type>, <protocol>);</span> <span style="color: rgb(0,0,255)">$sock</span> = @<a href="http://www.php.net/socket_create" target="_blank"><span style="color: rgb(0,0,102)">socket_create</span></a><span style="color: rgb(102,204,102)">(</span>AF_INET, SOCK_STREAM, SOL_TCP<span style="color: rgb(102,204,102)">)</span>; <span style="font-style: italic; color: rgb(128,128,128)">/*This next variable is the actual connection. The function socket_connect() will attempt to connect to the IP address. I am not sure if you can use domains in this field or not. After the IP address comes the port number that you are trying to get the status of. [Just so you all know ahead of time, socket_connect() will return an integer!] In this case, the script will check your localhost to see if the default http port (80) is open.*/</span> <span style="font-style: italic; color: rgb(128,128,128)">//PC: $sock2 = @socket_connect($sock, "<ip address>", <port/socket>);</span> <span style="color: rgb(0,0,255)">$sock2</span>= @<a href="http://www.php.net/socket_connect" target="_blank"><span style="color: rgb(0,0,102)">socket_connect</span></a><span style="color: rgb(102,204,102)">(</span><span style="color: rgb(0,0,255)">$sock</span>,<span style="color: rgb(255,0,0)">"127.0.0.1"</span>, <span style="color: rgb(204,102,204)">80</span><span style="color: rgb(102,204,102)">)</span>; <span style="font-style: italic; color: rgb(128,128,128)">/*These if and else if statements will compare the number that was recieved from the socket_connect() function with other numbers to return their status. In this instance, I made the script echo the status to be user friendly instead of the numbers 1, 2, or 3. I do not thing that pseudo code is really needed here. All you need to know is the integers that you get back from $sock2: 0: Connection timeout. This usually means that the port is open, but the program that usually uses it is not properly functioning. This is not always the case, just so you know, but this is the common case for me. 1: The port is open and accepting connections (presumably). 2: The connection was refused. That may mean that the port is closed.*/</span> <span style="color: rgb(177,177,0)">if</span><span style="color: rgb(102,204,102)">(</span><span style="color: rgb(0,0,255)">$sock2</span>==<span style="color: rgb(204,102,204)">0</span><span style="color: rgb(102,204,102)">)</span> <span style="color: rgb(102,204,102)">{</span> <a href="http://www.php.net/echo" target="_blank"><span style="color: rgb(0,0,102)">echo</span></a> <span style="color: rgb(255,0,0)">"Down! (Timeout)"</span>; <span style="color: rgb(102,204,102)">}</span> <span style="color: rgb(177,177,0)">else</span> <span style="color: rgb(177,177,0)">if</span><span style="color: rgb(102,204,102)">(</span><span style="color: rgb(0,0,255)">$sock2</span>==<span style="color: rgb(204,102,204)">1</span><span style="color: rgb(102,204,102)">)</span> <span style="color: rgb(102,204,102)">{</span> <a href="http://www.php.net/echo" target="_blank"><span style="color: rgb(0,0,102)">echo</span></a> <span style="color: rgb(255,0,0)">"Up!"</span>; <span style="color: rgb(102,204,102)">}</span> <span style="color: rgb(177,177,0)">else</span> <span style="color: rgb(177,177,0)">if</span><span style="color: rgb(102,204,102)">(</span><span style="color: rgb(0,0,255)">$sock2</span>==<span style="color: rgb(204,102,204)">2</span><span style="color: rgb(102,204,102)">)</span> <span style="color: rgb(102,204,102)">{</span> <a href="http://www.php.net/echo" target="_blank"><span style="color: rgb(0,0,102)">echo</span></a> <span style="color: rgb(255,0,0)">"Down! (Refused)"</span>; <span style="color: rgb(102,204,102)">}</span> <span style="font-style: italic; color: rgb(128,128,128)">/*If you get any data that does not seem right, you will get the error. The only numbers that I know that you can get if you do this correctly is 1, 2, and 3. Any others most likely means that you did something wrong with the variables.*/</span> <span style="color: rgb(177,177,0)">else</span> <span style="color: rgb(102,204,102)">{</span> <a href="http://www.php.net/echo" target="_blank"><span style="color: rgb(0,0,102)">echo</span></a> <span style="color: rgb(255,0,0)">"Unknown error..."</span>; <span style="color: rgb(102,204,102)">}</span> <span style="font-style: italic; color: rgb(128,128,128)">/*Now that everything has been executed, we no longer need to connection so it is dropped! The end!*/</span> <a href="http://www.php.net/socket_close" target="_blank"><span style="color: rgb(0,0,102)">socket_close</span></a><span style="color: rgb(102,204,102)">(</span><span style="color: rgb(0,0,255)">$sock</span><span style="color: rgb(102,204,102)">)</span>; <span style="color: rgb(0,0,0); font-weight: bold">?></span> </div>
试试其它关键字
检查端口
同语言下
.
用net匹配并替换iOS标准的emoji表情符号
.
处理带Emoji表情的的字符串
.
获取微信昵称时 过滤特殊字符
.
通过判断上传文件的头字符来判断文件的类型
.
模拟百度URL加密解密算法
.
以太坊检查地址是否合法
.
实现crontab解析类
.
获取每个月的开始和结束时间
.
图片上传工具类
.
APP手机应用信息采集
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
Dezai.CN
贡献的其它代码
(
4037
)
.
多线程Socket服务器模块
.
生成随机密码
.
清除浮动样式
.
弹出窗口居中
.
抓取url的函数
.
使用base HTTP验证
.
div模拟iframe嵌入效果
.
通过header转向的方法
.
Session操作类
.
执行sqlite输入插入操作后获得自动编号的ID
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3