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