SSL over TCP Client\server
Hi All ,
I need to write some basic tcp client/server that communicate over SSL
Its seems i managed to run the server side listen with SSL but i am missing the
client part.
If someone could advice me how to saet the client will be appreciated
Thanks
Server side
class SingleTCPHandler(socketserver.BaseRequestHandler):
"One instance per connection. Override handle(self) to customize action."
def handle(self):
try:
#print(self.server.serverset)
data = json.loads(self.request.recv(1024).decode('UTF-8').strip())
# process the data, i.e. print it:
#print(self.client_address)
print(data['AuthPass'],self.server.serverset['CryptKey'],self.server.serverset['Password'])
Authstart =
AuthMec(data['AuthPass'],self.server.serverset['CryptKey'],self.server.serverset['Password'])
Authstart.DecPass()
# send some 'ok' back
#self.server.serverset['QuarantineIp']
self.request.sendall(bytes(json.dumps({'QuarantineIp':self.server.serverset['QuarantineIp'],'SERVERIP':self.client_address[0]}),
'UTF-8'))
except Exception as e:
print("Exception wile receiving message: ", e)
class TcpSessionServer(socketserver.ThreadingMixIn, socketserver.TCPServer):
# Ctrl-C will cleanly kill all spawned threads
daemon_threads = True
# much faster rebinding
allow_reuse_address = True
test = "test"
def __init__(self, server_address, RequestHandlerClass):
socketserver.TCPServer.__init__(self, server_address,
RequestHandlerClass)
self.socket = ssl.wrap_socket(
self.socket, server_side=True,
certfile="cert.pem",do_handshake_on_connect=False)
#read configuraiton and seve it as class member
serverinit = GetServerInfo()
Clent Side
===
class TcpClientConnect:
def __init__(self,Datapayload,EnforcementHost,SrvPort):
self.Datapayload = Datapayload
self.EnforcementHost = EnforcementHost
self.SrvPort = SrvPort
def ContactEnforcementHost(self):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((self.EnforcementHost, int(self.SrvPort)))
s.send(bytes(json.dumps(self.Datapayload), 'UTF-8'))
#Waiting for results
result = s.recv(1024)
txres = result.decode('UTF-8')
print(txres)
jsresult = json.loads(txres)
print("%s"%jsresult)
s.close()
--
https://mail.python.org/mailman/listinfo/python-list
Python3 http.server.SimpleHTTPRequestHandler static files
Hello All, I need to create simple web server i am using following http.server.SimpleHTTPRequestHandler The class along with the web content is as follows structure main folder | |_httplocal https://mail.python.org/mailman/listinfo/python-list
How to get time (milisecond) of a python IO execution
Hi All
i am trying to test measure some IO execution in milliseconds , but bit confuse
about best method achive that under windows 7
i am using following code but not sure if its best or correct way since i have
two different results, which one should i take as results
and which is best way
please advice
Thanks
code exec results
1 loops, best of 3: 0.00925 usec per loop
3.827947176762156
run code
import timeit ,time
import datetime
import os
def main():
os.path.getsize("c:/video-2011-09-09-09-32-29.mp4")
if __name__ == '__main__':
t = timeit.Timer('main()')
print (t.timeit(1))
--
https://mail.python.org/mailman/listinfo/python-list
Cant get my tshark pharse to work
Hello All,
I am writing some code to get captured wiresahrk pcap file , using
popen.subprocess and extract some table csv format related to SMB, but for some
reason i can get the csv when using off-course regular cmd line its work
The code as follow below , maybe someone with exprience with such can help
Please advice
Thanks
import socket,subprocess
import os,time
sharkCall = ["tshark","-i" ,"1", "-w",os.getcwd() +'/smbsession.pcap']
sharkProc = subprocess.Popen(sharkCall,executable="C:/Program
Files/Wireshark/tshark.exe")
localip = socket.gethostbyname(socket.gethostname())
a = 0
while a ==0:
a = sharkProc.pid
time.sleep(2)
ipflt = ''
listip = socket.gethostbyname_ex('media.isilon.gefen.local')[2]
for ip in listip:
ipflt= ipflt+ "ip.addr==" + ip + "||"
ipflt = ipflt + "ip.addr==" + localip
if ipflt.endswith('||'):
ipflt = ipflt[:-2]
print (ipflt)
b= os.path.getsize("//media.isilon.gofn.local/Media/New Text Document.txt")
#statinfo
print(b)
#time.sleep(2)
sharkProc.kill()
tsharkCall =
["tshark","-r",'C:/traces_test/smbsession.pcap',"-Y",ipflt,"-T","fields","-e","ip.src","-e","ip.dst","-e","smb.file",\
"-e","smb.path","-e","smb.time","-e","tcp.time_delta",
"-E","header=y","-E","separator=,","-E","quote=d","-E","occurrence=f",\
'> '+os.getcwd() +'/tracetemp.csv']
tsharkProc = subprocess.Popen(tsharkCall,executable="C:/Program
Files/Wireshark/tshark.exe")
a = 0
while a ==0:
a = tsharkProc.pid
time.sleep(2)
print ('Finished')
--
https://mail.python.org/mailman/listinfo/python-list
Write list to new column in existent csv
Hello Group, I am tryin to figure how to write a list i have as follows ['info', '19987→445 [SYN] Seq=0 Win=8192 Len=0 MSS=1460 WS=256 SACK_PERM=1\n', '445→19987 [SYN, ACK] Seq=0 Ack=1 Win=65535 Len=0 MSS=1460 WS=64 SACK_PERM=1\n', '19987→445 [ACK] Seq=1 Ack=1 Win=65536 Len=0\n', 'Negotiate Protocol Request\n', '[TCP Retransmission] Negotiate Protocol Request\n', '445→19987 [ACK] Seq=1 Ack=160 Win=1049536 Len=0\n', 'Negotiate Protocol Response\n', 'Negotiate Protocol Request\n', 'Negotiate Protocol Response\n', 'Session Setup Request, NTLMSSP_NEGOTIATE\n', 'Session Setup Response, Error: STATUS_MORE_PROCESSING_REQUIRED, NTLMSSP_CHALLENGE\n', 'Session Setup Request, NTLMSSP_AUTH, User: GEFEN\\tbaror\n', '445→19987 [ACK] Seq=768 Ack=1016 Win=1049728 Len=0\n', 'Session Setup Response\n', 'Tree Connect Request Tree: media.isilon.gefen.local\\Media\n', 'Tree Connect Response\n', 'Create Request File: New Text document.txt\n', 'Create Response File: New Text document.txt\n', 'GetInfo Request FS_INFO/SMB2_FS_INFO_01 File: New Text document.txt;GetInfo Request FS_INFO/SMB2_FS_INFO_05 File: New Text document.txt\n'] To a a csv to for example the 3rd column , i am really got stacked here i tried few codes with csv.writerow() but didn't got it work ,will really appreciate if someone could help me with that Please advice Thanks The csv ip.src,ip.dst,smb.file,smb2.filename,smb.path,smb2.tree,smb.time,smb2.time,smb.cmd,smb2.cmd,tcp.time_delta,tcp.analysis.ack_rtt,tcp.analysis.ack_lost_segment,tcp.analysis.duplicate_ack,tcp.analysis.lost_segment,tcp.analysis.retransmission,tcp.analysis.out_of_order,tcp.analysis.window_full,tcp.analysis.window_update,tcp.analysis.zero_window 172.18.2.54,172.18.5.64,0, 172.18.5.64,172.18.2.54,0.003322,0.003322 172.18.2.54,172.18.5.64,0.29,0.29 172.18.2.54,172.18.5.64,,,114,,0.84, 172.18.2.54,172.18.5.64,,,114,,0.300507,1 172.18.5.64,172.18.2.54,0.000114,0.300621 172.18.5.64,172.18.2.540,0.000266, 172.18.2.54,172.18.5.640,0.92,0.92 172.18.5.64,172.18.2.54,,0.000192,,0,0.000192,0.000192 172.18.2.54,172.18.5.641,0.000589,0.000589 172.18.5.64,172.18.2.54,,0.001788,,1,0.001788,0.001788 172.18.2.54,172.18.5.641,0.000193,0.000193 172.18.5.64,172.18.2.54,0.005582,0.005582 172.18.5.64,172.18.2.54,,0.008014,,1,0.002432, 172.18.2.54,172.18.5.64\\media.isilon.gefen.local\Media3,0.000203,0.000203 172.18.5.64,172.18.2.54,,0.000458,,3,0.000458,0.000458 172.18.2.54,172.18.5.64,,New Text document.txt,,\\media.isilon.gefen.local\Media5,0.000189,0.000189 172.18.5.64,172.18.2.54\\media.isilon.gefen.local\Media,,0.000274,,5,0.000274,0.000274 -- https://mail.python.org/mailman/listinfo/python-list
