QQ登录

只需要一步,快速开始

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

tcp的socket连接报文测试工具

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

1189

主题

4

听众

2934

积分

该用户从未签到

跳转到指定楼层
1#
发表于 2024-3-31 17:21 |只看该作者 |倒序浏览
|招呼Ta 关注Ta
# -*- coding: utf-8 -*-# l* ~8 v) _5 y* z5 ]
import socket; o9 U1 y* C9 f5 L( ~% l1 H. C) H
from myutil import *2 I& Z- A7 r- g, H" E3 n; @4 V' }
from binascii import unhexlify as unhex
& @' p7 n8 s  n9 y' Nfrom ctypes import *
8 x  U9 b$ @" Wdll = cdll.LoadLibrary('mydll.dll')
4 V* F/ y" M, j" [print 'begin load mydll..'( {9 V) W9 c3 n: J3 o
HOST, PORT = "192.168.51.28", 5800
# e! D4 r) ]0 l! X* s$ d7 E+ }% x  Wsd ="1234567812345678"
7 S3 b# R4 [8 Y0 v2 o; A) _# Create a socket (SOCK_STREAM means a TCP socket)
' b! C1 |0 G1 e, s6 j9 qsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
" t" t8 `, I# _: s; ktry:  D1 K0 E, ~& a' G) R" ^
    # Connect to server and send data
- B5 o/ Q- J/ C" E  A1 e$ M& S% g    sock.connect((HOST, int(PORT))
4 o: Z7 w  K( W& ^' e; w% j9 x    print "Sent1 OK:"
6 p. ?* y; ~' m" v; J0 g  I    print sd, [! Q1 L5 X# z" O. B
    # Receive data from the server and shut down
% U4 z! n' a& X0 T/ n" d    received = sock.recv(1024)3 H/ S4 Q9 b& |+ T( k% t
    print "Received:"4 p" \6 w. F% y$ l( J6 ^# c
    print_hex(received)
1 ?! n8 ~+ }8 F( @8 }' [    print  'received len is 0x%02x' %(len(received)), {7 `% [8 W) w# g
    print  'received data analysis...'
1 R6 M2 Z$ U$ C7 g) r/ D    re1=received[0:4]
" X$ a! J- k) t    print_hex(re1)3 J+ s3 O4 b) V' t% `6 Q# i' _- w
    re1=received[4:6]
' v: [4 y) x7 V, [3 P, U5 `6 o    print_hex(re1)9 `2 y6 [& J3 B/ Y1 |% Z4 x2 t
    re1=received[6:10]
* V% O( O1 g2 E% r0 x    print_hex(re1)
% u3 A; I+ ^2 Z* G1 `: M    re1=received[10:16]& f5 [1 [  B9 E
    print_hex(re1)5 _# @4 ~; j. F8 ^- Y

4 i. b) X2 O0 {! r" R    #pack2 send
+ K. D& e; J' o0 [0 r7 T7 E2 m    sock.send(sd2.decode('hex'))
- |, O6 V0 `- }    print "Sent2 OK:"- ~5 C- \, F) B$ V: h
    print sd2
5 R: Q7 K/ {' k8 T& w4 J' ?, F    # Receive data from the server and shut down
& u  L" [4 |- a+ }8 l4 [    received1 = sock.recv(1024)
, H. Y8 ]/ N: {    print "Received1:"
+ B7 b6 Y" o! x    print_hex(received1)
5 R+ P0 X# D, G8 ]4 J! j    print  'received1 len is 0x%02x' %(len(received1))
' c- |! ?. d2 }" g+ [
+ E) C2 W4 x$ W# |; Zfinally:
3 F& V) k  {' v- E" s% M  L% k    sock.close()3 x# M7 E: S" `4 |, l& d

9 ?1 X/ \- {& l1 e; x0 xs=raw_input('press any key to continue...')
) |2 _$ ~9 O* `$ P, R( N1 M' _3 L" c& d9 c8 ]5 G

5 f3 Q  w. ?  V7 x( 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-6-2 22:36 , Processed in 0.459064 second(s), 51 queries .

回顶部