- 在线时间
- 480 小时
- 最后登录
- 2026-6-1
- 注册时间
- 2023-7-11
- 听众数
- 4
- 收听数
- 0
- 能力
- 0 分
- 体力
- 7823 点
- 威望
- 0 点
- 阅读权限
- 255
- 积分
- 2934
- 相册
- 0
- 日志
- 0
- 记录
- 0
- 帖子
- 1174
- 主题
- 1189
- 精华
- 0
- 分享
- 0
- 好友
- 1
该用户从未签到
 |
# -*- 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
|