Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #78908 > unrolled thread
| Started by | Tal Bar-Or <tbaror@gmail.com> |
|---|---|
| First post | 2014-10-09 11:45 -0700 |
| Last post | 2014-10-11 00:59 -0700 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.lang.python
Cant get my tshark pharse to work Tal Bar-Or <tbaror@gmail.com> - 2014-10-09 11:45 -0700
Re: Cant get my tshark pharse to work sandra.baror@gmail.com - 2014-10-11 00:59 -0700
| From | Tal Bar-Or <tbaror@gmail.com> |
|---|---|
| Date | 2014-10-09 11:45 -0700 |
| Subject | Cant get my tshark pharse to work |
| Message-ID | <f9cbf4cf-62fc-4b7c-82ef-5050bafca542@googlegroups.com> |
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')
[toc] | [next] | [standalone]
| From | sandra.baror@gmail.com |
|---|---|
| Date | 2014-10-11 00:59 -0700 |
| Message-ID | <3d4596e9-f763-497b-918f-56fab2983754@googlegroups.com> |
| In reply to | #78908 |
On Thursday, October 9, 2014 9:46:10 PM UTC+3, Tal Bar-Or wrote:
> 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')
the problematic code where
sharkCall = ["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")
i changed it to as follows below and now its works , thanks
tsharkCall = '"' +os.environ["ProgramFiles"]+'/Wireshark/tshark.exe"' +" -r "+os.getcwd() +'/smbsession.pcap'+" -Y "+'"'+toto+'"'+" -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() +"/trac_session.csv"
tsharkProc = subprocess.Popen(tsharkCall,shell=True)
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web