-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmd_client.py
executable file
·88 lines (68 loc) · 1.97 KB
/
cmd_client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/python
#-*- coding:utf-8 -*-
import sys
import socket
# import threading
# from time import sleep
from datetime import datetime
'''
class SockClient(threading.Thread):
def __init__(self, host_ip, host_port):
threading.Thread.__init__(self)
self.running = False
self.sock = socket.socket()
self.sock.settimeout(20) # 20 seconds
try:
self.sock.connect((host_ip, host_port))
except socket.error, e:
print("Socket Connect Error:%s" % e)
exit(1)
print("connect success")
self.running = True
self.error_cnt = 0
def run(self):
while self.running:
try:
send_data = '\x12\x34\x56'
self.sock.send(send_data)
data = self.sock.recv(1024)
if len(data) > 0:
self.error_cnt = 0
recv_data = data.encode('hex')
print 'recv:', recv_data
sleep(1)
except socket.error, e:
print 'socket running error:', str(e)
break
print 'SockClient Thread Exit\n'
'''
# def text_search(types, sort_field, search_txt):
if __name__ == "__main__":
# print datetime.now()
method = "text_search"
types = "cmds"
sort_field = "num"
search_txt = " ".join(sys.argv[1:])
search = ";".join([method, search_txt, types, sort_field])
HOST='localhost'
PORT = 21590
socket1 = socket.socket()
socket1.connect((HOST, PORT))
socket1.send(search)
data = socket1.recv(65536)
# print datetime.now()
print data
'''
sock_client = SockClient('192.168.99.219', 8093)
sock_client.start()
try:
while True:
sleep(1)
if not sock_client.is_alive():
break
except KeyboardInterrupt:
print 'ctrl+c'
sock_client.running = False
sock_client.join()
print 'exit finally'
'''