操作系统:linux
软件环境:Python 2.7.3
用法:
代码如下:
$ ./MonSocket.py
# This is check the URI or Socket of the script #
Usage:
./MonSocket.py -d URL; This is Http protocol
./MonSocket.py -s socket IP or domain; This is Socket protocol
./MonSocket.py -p port; This is Socket port
./MonSocket.py -n ; Total number of requests
./MonSocket.py -c ; Number of concurrent requests
./MonSocket.py -t ; Timeout time(s),socket default is 1s,http default is 5s
For exampale: ./MonSocket.py -d www.weibo.com/index.php -n 200 -c 10 -t 2
For exampale: ./MonSocket.py -s 10.210.214.249 -p 80 -n 200 -c 50 -t 3
代码:
代码如下:
#!/usr/bin/env python
# encoding: utf-8
#
# Write by 飞奔的蜗牛-Bob
import os,sys
import getopt,re
import socket,threading,urllib2
def usage():
print '# This is check the URI or Socket of the script #'
print 'Usage:'
print " %s -d URL; This is Http protocol" %sys.argv[0]
print " %s -s socket IP or domain; This is Socket protocol" %sys.argv[0]
print " %s -p port; This is Socket port" %sys.argv[0]
print " %s -n ; Total number of requests" %sys.argv[0]
print " %s -c ; Number of concurrent requests" %sys.argv[0]
print " %s -t ; Timeout time(s),socket default is 1s,http default is 5s" %sys.argv[0]
print "For exampale: %s -d www.weibo.com/index.php -n 200 -c 10 -t 2" %sys.argv[0]
print "For exampale: %s -s 10.210.214.249 -p 80 -n 200 -c 50 -t 3" %sys.argv[0]
def Detect_url(url,sign):
if timeout:
time = int(timeout)
else:
time = 5
urllib2.socket.setdefaulttimeout(time)
request = urllib2.Request('http://%s' %(url))
try:
ret = urllib2.urlopen(request)
except urllib2.URLError,e:
if hasattr(e,"reason"):
port_timeout.append('1')
elif hasattr(e,"code"):
if re.findall('^3\d*','%s' %e.code):
port_normal.append('1')
if re.findall('^404\d*','%s' %e.code):
port_404.append('1')
if re.findall('^403\d*','%s' %e.code):
port_403.append('1')
if re.findall('^500\d*','%s' %e.code):
port_500.append('1')
if re.findall('^502\d*','%s' %e.code):
port_502.append('1')
if re.findall('^503\d*','%s' %e.code):
port_503.append('1')
else:
port_other.append('1')
else:
port_normal.append('1')
def Detect_socket(server,port):
sign = 0
if timeout:
time = int(timeout)
else:
time = 1
socket.setdefaulttimeout(time)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
ret = s.connect((server, int(port)))
except socket.error, e:
if re.findall('^timed\ out*','%s' %e):
socket_timeout.append('1')
sign = 1
else:
print '%s' %e
sys.exit(2)
else:
socket_normal.append('1')
sign = 1
if sign == 0:
s.close()
def print_out():
if url_mod:
print 'URL:'
print 'timeout:[%s]' %len(port_timeout)
print 'normal:[%s]' %len(port_normal)
print '\033[;31mError_403:[%s]\tError_404:[%s]\033[0m' %(len(port_403),len(port_404))
print '\033[;31mError_500:[%s]\tError_502:[%s]\tError_503:[%s]\033[0m' %(len(port_500),len(port_502),len(port_503))
print '\033[;31mError_other:[%s]\033[0m' %len(port_other)
if sock_mod:
print 'Socket:'
print 'timeout:[%s]' %len(socket_timeout)
print 'normal:[%s]' %len(socket_normal)
def main():
if sock_mod:
dest_arg1 = sock_mod
dest_arg2 = dport
dest_function = Detect_socket
elif url_mod:
dest_arg1 = url_mod
dest_arg2 = ''
dest_function = Detect_url
else:
sys.exit()
total = int(dcount)
concurrent = int(dconcurrent)
n = 0
sign = 0
lastnu = total%concurrent
while 1:
threads = []
if n + concurrent > total:
nloops = range(n,total)
sign = 1
else:
nloops = range(n,n+concurrent)
for i in nloops:
t = threading.Thread(target=dest_function,args=(dest_arg1,dest_arg2))
threads.append(t)
if sign == 1:
th_nu = lastnu
else:
th_nu = concurrent
for i in range(th_nu):
threads[i].start()
for i in range(th_nu):
threads[i].join()
n = n + concurrent
if sign == 1:
break
print_out()
if __name__=='__main__':
try:
opts,args=getopt.getopt(sys.argv[1:],"hd:s:p:n:c:t:")
except getopt.GetoptError:
usage()
sys.exit(2)
port_timeout = []
port_normal = []
port_403= []
port_404 = []
port_500 = []
port_502 = []
port_503 = []
port_other = []
socket_normal = []
socket_timeout = []
dcount = 0
url_mod = ''
sock_mod = ''
dport = ''
dconcurrent = 0
timeout = 0
if opts:
for opt,arg in opts:
if opt == '-h':
usage()
sys.exit()
if opt == '-d':
url_mod = arg
if opt == '-s':
sock_mod = arg
if opt == '-p':
dport = arg
if opt == '-n':
dcount = arg
if opt == '-c':
dconcurrent = arg
if opt == '-t':
timeout = arg
if url_mod and dcount and dconcurrent:
main()
elif sock_mod and dport and dcount and dconcurrent:
main()
else:
usage()
else:
usage()
sys.exit()

一、基于TCP协议的socket套接字编程1、套接字工作流程先从服务器端说起。服务器端先初始化Socket,然后与端口绑定(bind),对端口进行监听(listen),调用accept阻塞,等待客户端连接。在这时如果有个客户端初始化一个Socket,然后连接服务器(connect),如果连接成功,这时客户端与服务器端的连接就建立了。客户端发送数据请求,服务器端接收请求并处理请求,然后把回应数据发送给客户端,客户端读取数据,最后关闭连接,一次交互结束,使用以下Python代码实现:importso

SpringBoot端第一步,引入依赖首先我们需要引入WebSocket所需的依赖,以及处理输出格式的依赖com.alibabafastjson1.2.73org.springframework.bootspring-boot-starter-websocket第二步,创建WebSocket配置类importorg.springframework.context.annotation.Bean;importorg.springframework.context.annotation.Config

本篇文章给大家带来了关于php+socket的相关知识,其中主要介绍了IO多路复用,以及php+socket如何实现web服务器?感兴趣的朋友下面一起来看一下,希望对大家有帮助。

php socket无法连接的解决办法:1、检查php是否开启socket扩展;2、打开php.ini文件,检查“php_sockets.dll”是否被加载;3、取消“php_sockets.dll”的注释状态即可。

本篇文章给大家带来了关于php+socket的相关知识,其中主要介绍了什么是socket?php+socket如何实现客户端与服务端数据传输?感兴趣的朋友下面一起来看一下,希望对大家有帮助。

随着互联网的发展,文件传输成为人们日常工作和娱乐中不可或缺的一部分。然而,传统的文件传输方式如邮件附件或文件分享网站存在一定的限制,无法满足实时性和安全性的需求。因此,利用PHP和Socket技术实现实时文件传输成为了一种新的解决方案。本文将介绍利用PHP和Socket技术实现实时文件传输的技术原理、优点和应用场景,并通过具体案例来演示该技术的实现方法。技术

C#中常见的网络通信和安全性问题及解决方法在当今互联网时代,网络通信已经成为了软件开发中必不可少的一部分。在C#中,我们通常会遇到一些网络通信的问题,例如数据传输的安全性、网络连接的稳定性等。本文将针对C#中常见的网络通信和安全性问题进行详细讨论,并提供相应的解决方法和代码示例。一、网络通信问题网络连接中断:网络通信过程中,可能会出现网络连接的中断,这会导致

本篇文章给大家带来了关于php+socket的相关知识,其中主要介绍了怎么使用php原生socket实现一个简易的web聊天室?感兴趣的朋友下面一起来看一下,希望对大家有帮助。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

DVWA
Damn Vulnerable Web App (DVWA) 是一個PHP/MySQL的Web應用程序,非常容易受到攻擊。它的主要目標是成為安全專業人員在合法環境中測試自己的技能和工具的輔助工具,幫助Web開發人員更好地理解保護網路應用程式的過程,並幫助教師/學生在課堂環境中教授/學習Web應用程式安全性。 DVWA的目標是透過簡單直接的介面練習一些最常見的Web漏洞,難度各不相同。請注意,該軟體中

PhpStorm Mac 版本
最新(2018.2.1 )專業的PHP整合開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

MinGW - Minimalist GNU for Windows
這個專案正在遷移到osdn.net/projects/mingw的過程中,你可以繼續在那裡關注我們。 MinGW:GNU編譯器集合(GCC)的本機Windows移植版本,可自由分發的導入函式庫和用於建置本機Windows應用程式的頭檔;包括對MSVC執行時間的擴展,以支援C99功能。 MinGW的所有軟體都可以在64位元Windows平台上運作。

ZendStudio 13.5.1 Mac
強大的PHP整合開發環境