QQ登录

只需要一步,快速开始

 注册地址  找回密码
查看: 2340|回复: 0
打印 上一主题 下一主题

tcp的socket连接报文测试工具

[复制链接]
字体大小: 正常 放大

1186

主题

4

听众

2923

积分

该用户从未签到

跳转到指定楼层
1#
发表于 2024-3-31 17:21 |只看该作者 |倒序浏览
|招呼Ta 关注Ta
# -*- coding: utf-8 -*-5 F  {, E. w0 o1 d" c! U5 P5 t
import socket+ S/ W4 R+ x. Z1 d0 \# B& t3 c
from myutil import *6 ]! Q& I. H' k3 M9 l/ N
from binascii import unhexlify as unhex" q% S2 O: {' Q' x9 u
from ctypes import *& k* O8 n! {1 D# r8 d, U; M2 D
dll = cdll.LoadLibrary('mydll.dll')# c" @. Z7 L9 k
print 'begin load mydll..'( `& d" _( {/ Y' l2 h
HOST, PORT = "192.168.51.28", 58009 f" a4 ]  s$ V- B+ @
sd ="1234567812345678") P% A( f: }* C$ x
# Create a socket (SOCK_STREAM means a TCP socket)
( D2 g# a, X2 R7 ]; }sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)! u* R8 f  j8 j9 M
try:1 l9 d7 W& D$ @$ c2 U( q
    # Connect to server and send data  Q3 }9 @+ j. t; U) A
    sock.connect((HOST, int(PORT))
; u& p4 Q0 Y, P# I& _8 ?) c    print "Sent1 OK:"
$ G6 U6 s& u$ F. f1 j# y+ {% b5 R    print sd
" o/ n& D3 ~* O0 o% B    # Receive data from the server and shut down
3 [  ]9 C/ r' L' o/ J7 O    received = sock.recv(1024)
$ h* A& ~  H) P  L. f& t) a    print "Received:"
% {; G& I' L& [& A) A    print_hex(received)
% q" m" ~9 O% i5 _" m( t1 q    print  'received len is 0x%02x' %(len(received))9 A- E  _: a7 u! S- f# a/ n" P0 h, U
    print  'received data analysis...'
% t( r) u1 O* J) g& p    re1=received[0:4]
7 u3 E, d  V! I! m- L+ e    print_hex(re1)
5 l7 z- j; P7 y' n- i! p    re1=received[4:6]
) v7 x$ T& f* {$ k% V    print_hex(re1)  @: p2 r& O6 s" p
    re1=received[6:10]
5 X/ D1 A& E$ L! |! H" ^; }) Q# Q  D    print_hex(re1)
2 }) H2 d& f) ]! X; ]; r2 t  \6 {% V    re1=received[10:16]
" v) g0 {2 w; b4 V) r9 }, }! f. c    print_hex(re1)
# T, `0 u( u8 v- ?0 ?2 E) g# C1 d  F
9 U  h, G& ~( i! e' y$ ]0 U    #pack2 send
$ V% d7 I1 ^, y. J( ~    sock.send(sd2.decode('hex'))
0 {  `% }) G( }$ u6 A7 ~& n    print "Sent2 OK:"8 F+ N  i9 [0 V7 `! k7 k
    print sd2- e! n9 ^9 l1 g6 q9 G# M" ?
    # Receive data from the server and shut down
* g) O5 c. z3 v# l0 Z5 d/ C    received1 = sock.recv(1024)
, G* |  y$ O+ D5 L2 s( |- {9 P0 c* @6 e    print "Received1:"
6 G' H7 n! I/ g6 v1 K5 w    print_hex(received1)
7 c( G/ d, k$ v) U5 f    print  'received1 len is 0x%02x' %(len(received1))
0 G; v( k/ G: ]5 @! F/ n! f
4 G& I2 d( [% p; j/ Pfinally:
# W- v' A" u# A  P9 j    sock.close()& G  r* Y, C4 z5 a0 l& q
1 N- q8 K# Q5 y1 x- B. Z
s=raw_input('press any key to continue...')
6 u. n" _$ u5 O, I+ W3 h5 s2 h! q
' s7 D/ j5 d3 X3 l* Y: v8 G8 Z4 @
& E$ Q1 {( s- ^5 P  M
zan
转播转播0 分享淘帖0 分享分享0 收藏收藏0 支持支持0 反对反对0 微信微信
您需要登录后才可以回帖 登录 | 注册地址

qq
收缩
  • 电话咨询

  • 04714969085
fastpost

关于我们| 联系我们| 诚征英才| 对外合作| 产品服务| QQ

手机版|Archiver| |繁體中文 手机客户端  

蒙公网安备 15010502000194号

Powered by Discuz! X2.5   © 2001-2013 数学建模网-数学中国 ( 蒙ICP备14002410号-3 蒙BBS备-0002号 )     论坛法律顾问:王兆丰

GMT+8, 2026-4-19 14:12 , Processed in 0.461214 second(s), 51 queries .

回顶部