QQ登录

只需要一步,快速开始

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

tcp的socket连接报文测试工具

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

1186

主题

4

听众

2923

积分

该用户从未签到

跳转到指定楼层
1#
发表于 2024-3-31 17:21 |只看该作者 |倒序浏览
|招呼Ta 关注Ta
# -*- coding: utf-8 -*-+ ~4 X8 f2 A2 `/ O+ X9 V
import socket0 M; ^+ V8 A' m) X/ d
from myutil import *6 |7 n- p/ D9 m) v" D
from binascii import unhexlify as unhex' l) Q& b, }1 F
from ctypes import *) G, L( W$ M9 `. _: S( w1 A
dll = cdll.LoadLibrary('mydll.dll')3 s$ d8 }0 L* C
print 'begin load mydll..'
9 R' @5 ?8 Y" p0 d! NHOST, PORT = "192.168.51.28", 5800
' Q$ C6 G5 y5 esd ="1234567812345678"
4 }, A& e1 b4 [. A* G9 ^# Create a socket (SOCK_STREAM means a TCP socket)' }# v7 v1 e/ T9 Q
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)6 [) G6 z2 \) f/ K' U6 P
try:
. W& K, U  d6 V+ ~    # Connect to server and send data, h0 t* N( Q' y: b# u% t$ t6 O
    sock.connect((HOST, int(PORT))
/ L) [  Z; e- }# N. u8 ?* D) S0 y" ^    print "Sent1 OK:"0 \0 x6 ]: i; A6 @  h3 i/ K; ~
    print sd
. x: o/ I+ U8 F    # Receive data from the server and shut down2 M) G8 n0 T+ D* U, J
    received = sock.recv(1024)& \1 B5 n' F5 K6 m4 A( }0 v; D. z
    print "Received:"$ h6 r! N$ ^, Y: w' h" [* S" U; k+ A( p
    print_hex(received)
" |: b% t+ a' K8 d( g3 q( w& \4 O    print  'received len is 0x%02x' %(len(received))6 S& A/ R: L6 X  X" d  ^8 d; e" b) g  g
    print  'received data analysis...'+ v* ?. ?+ g  F4 r' Y7 T
    re1=received[0:4]
6 N! Z  X) y5 n$ d    print_hex(re1)% ~) Y  l0 ?2 Y! @% ?! N
    re1=received[4:6]9 ~1 D8 n/ m6 N) `/ @! ?
    print_hex(re1)
/ ~9 I" F; ~5 S: O( t$ Y7 h    re1=received[6:10]
+ G) u. g% s1 B3 r) J3 B5 a    print_hex(re1)
( Y/ e( C! j8 n7 n/ X1 u  D9 W    re1=received[10:16]
7 J1 ~1 u: l2 \% v# I7 A- z    print_hex(re1)$ e3 s; b7 h. n0 R" S

2 B/ b& }6 J5 c+ r* v: A3 z    #pack2 send
3 H3 t: }% ~0 K    sock.send(sd2.decode('hex'))! s( z: e/ C5 P  t' A) `
    print "Sent2 OK:"
3 x% Q7 j7 K& Z. s1 a6 O8 O    print sd2  s9 P. c9 f5 z0 ?& d9 V: }
    # Receive data from the server and shut down
% Z& N: ]9 F7 }3 q" w    received1 = sock.recv(1024): @  o8 [0 m. w8 H1 b
    print "Received1:"# ^. j7 |. D$ R# `- n# L9 z% @
    print_hex(received1)
: n& f4 \% ~, |) z2 s$ u    print  'received1 len is 0x%02x' %(len(received1))
/ c1 n' l: B# G( a3 I& Z4 _) b) {6 t
- }+ N( w. M! b+ B: P0 {finally:; C" h# s, g* o
    sock.close()
* M4 N/ b0 K5 Q, E* r2 _6 x* n8 I$ ^! b! [7 d. h+ o
s=raw_input('press any key to continue...')
6 X( `/ o' X% {; y
& C$ \- o/ n/ b4 d: v/ r+ L$ W
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-18 06:48 , Processed in 0.369801 second(s), 51 queries .

回顶部