0

hi,
i'm novice user in python and i want to capture data at a specific port using python script.Please suggest me the approach.

Same data i'm able to write into a file using linux command:
tethereal -i any "port 9060" -w sam.txt

I want to accomplish the above task using python script.


Thanks in Advance,
bharat.

4
Contributors
3
Replies
5
Views
8 Years
Discussion Span
Last Post by Azeriah
0

I suggest a subprocess, like this

from subprocess import Popen, PIPE
tethereal = Popen('tethereal -i any "port 9060"', shell=True, stdout=PIPE)
while True:
    data = tethereal.stdout.read(1024)
    if data == '':
        break
    print data
0

Hi,

I need to get the gps receiver data....by using telnet

when i am enter the below command in terminal(UBUNTU 8.10):

"telnet localhost 2947" its giving the data like below in terminal..
Trying 127.0.0.1...
Connected, to localhost.
Escape character is '^]'.
r (here if i press r and enter the the below data will come on terminal)
GPSD,R=1
$GPGSV,3,1,11,08,16,328,40,11,36,127,00,28,33,283,39,20,11,165,00*71
$GPGSV,3,2,11,17,24,208,39,27,11,097,00,13,87,174,00,19,31,042,00*70
$GPGSV,3,3,11,25,43,033,38,03,07,037,00,23,47,150,00*44
$GPGGA,111503,0833.6323,N,07652.7685,E,1,04,1.60,16.69,M,-94.088,M,,*58
$GPRMC,111503,A,0833.6323,N,07652.7685,E,0.1866,256.540,220609,,*2A
-
-
-
when i am using above script....

1 #!/usr/bin/env python
2
3 from subprocess import Popen, PIPE
4
5 gpsreceiver = Popen('telnet localhost 2947', shell=True, stdout=PIPE)
6 while True:
7 data = gpsreceiver.stdout.read(1024)
8 if data == '':
9 break
10 print data

its giving all the log...but what i need, i need to read each line, if the line is start with $GPRMC...that has to copy into newfile.
in the above,
$GPRMC,111503,A,0833.6323,N,07652.7685,E,0.1866,256.540,220609,,*2A
line has to open file gps.txt and save it.
Please help me how to do it?

Thanks,

sincerely,
sravan

0

You could use the startsWith() method on data to ascertain whether or not the stuff in data starts with $GPRMC?

New code:

from subprocess import Popen, PIPE
tethereal = Popen('tethereal -i any "port 9060"', shell=True, stdout=PIPE)
while True:
    data = tethereal.stdout.read(1024)
    if data == '':
        break
    else if data.startsWith("$GPRMC"):
        print data

That should do the trick, but no guarantees - a little shaky on my Python. I don't know what the tethereal.stdout.read(1024) puts into data so I can't be 100% sure if the startsWith() method will work but give it a try.

Good luck to you!

Regards,
George.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.