QQ登录

只需要一步,快速开始

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

tcp的socket连接报文测试工具

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

1189

主题

4

听众

2934

积分

该用户从未签到

跳转到指定楼层
1#
发表于 2024-3-31 17:21 |只看该作者 |倒序浏览
|招呼Ta 关注Ta
# -*- coding: utf-8 -*-
* t$ S6 V4 u0 S' L5 S6 Bimport socket5 @: L0 @- @1 \0 f4 l0 O. N
from myutil import ** e) C" ?4 O9 `5 W1 v/ I+ d" |6 B
from binascii import unhexlify as unhex# \# e: Y: W7 }9 f) Y
from ctypes import *
9 r2 K% c( I% |: L" pdll = cdll.LoadLibrary('mydll.dll')
8 \. q1 R! t7 A* }print 'begin load mydll..'
3 f, t! D3 @! D$ E% }: F, P7 vHOST, PORT = "192.168.51.28", 5800. \2 v; K; ~+ r/ d& k0 C! G
sd ="1234567812345678"! O1 G: @  Z, A. @# F1 n+ J( [
# Create a socket (SOCK_STREAM means a TCP socket)
7 k0 ~. J: e' O/ qsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
: p( O0 R* P* g" t, {- G% g1 w" O9 T4 gtry:
% Y$ d( \1 Y# E- B    # Connect to server and send data
( G9 e% ~' X; h0 g* _( n    sock.connect((HOST, int(PORT)). V$ F" }$ C! x0 E0 K
    print "Sent1 OK:"
/ c6 `7 L, A) G& G4 v    print sd
5 E& I% o6 }' l9 G1 `    # Receive data from the server and shut down2 o9 I/ [! h3 D5 B$ ]8 B
    received = sock.recv(1024)" D9 U# n+ K. o" z. A
    print "Received:"' F5 G  A" f. {% x! o: ^3 s
    print_hex(received)+ B5 x5 q9 w/ \1 [
    print  'received len is 0x%02x' %(len(received))+ F$ V8 J( m: g; N: _
    print  'received data analysis...'( W3 @  t% s- \' I
    re1=received[0:4]% m" t; F$ ]% L7 O5 U2 ]
    print_hex(re1)
% N% F. w9 K: n; j2 J2 @9 @    re1=received[4:6]: r( v/ q7 f3 M8 M& ~6 c5 W
    print_hex(re1)
0 E( F' ]3 h6 i- k% w    re1=received[6:10]& W  c: w  a5 t* E2 T( r( g  o
    print_hex(re1)& K4 M8 ?- E# }9 {
    re1=received[10:16]8 n; Q* r. d. B$ v- \+ Z
    print_hex(re1)7 P( i/ Z* i3 h! F0 b* A

1 A' `# B) U- o; W    #pack2 send
7 B6 A1 f5 [! P+ L- S    sock.send(sd2.decode('hex'))
* U' h' U5 g% I- C$ z    print "Sent2 OK:"
' l: D3 s0 g0 g3 i# C8 B. z    print sd2# Q. N9 c( [  G0 Y- X
    # Receive data from the server and shut down! W# N1 V4 B. f6 }# r" ~3 g
    received1 = sock.recv(1024)
# l+ t5 x5 a0 K3 S8 n1 ]    print "Received1:"
0 F2 o" `/ l& r    print_hex(received1)
8 O% W* a, ], T- \    print  'received1 len is 0x%02x' %(len(received1))% \& K) v+ d/ ]0 |7 @
2 b7 ~4 W# [( q
finally:
/ d* F) X6 D$ }6 H% I6 ?    sock.close()
" o" B8 ?8 K9 A; v: Y0 K2 a; f& P- g7 b+ L! y( x. g4 q
s=raw_input('press any key to continue...')# @& R  M# x4 K5 ~! i! q$ l

7 p3 J( }6 a: ~  y! O7 o8 N% }; b! M- Z, {0 b
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-7-18 06:12 , Processed in 0.402129 second(s), 51 queries .

回顶部