Author: ks156
Date: 2008-12-04 12:57:47 +0100 (Thu, 04 Dec 2008)
New Revision: 3007

Modified:
   
software_suite_v2/software/http_server_resources/chatter_tux/trunk/ChatterTux/chattertux.py
Log:
* Now, the TCP frames are parsed. I detect the MSN frame, and send the text to
  the chattertux resource
* Open only the active iface
* Ping google.com and wait for the link goes up
* Added header


Modified: 
software_suite_v2/software/http_server_resources/chatter_tux/trunk/ChatterTux/chattertux.py
===================================================================
--- 
software_suite_v2/software/http_server_resources/chatter_tux/trunk/ChatterTux/chattertux.py
 2008-12-03 21:07:13 UTC (rev 3006)
+++ 
software_suite_v2/software/http_server_resources/chatter_tux/trunk/ChatterTux/chattertux.py
 2008-12-04 11:57:47 UTC (rev 3007)
@@ -1,11 +1,36 @@
+#!/usr/bin/python
 #-*- coding:Utf-8 -*-
 
+# Tuxdroid ChatterTux : network packet annalyser.
+#
+# Copyright (C) 2008 C2ME Sa <[EMAIL PROTECTED]>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+# 02111-1307, USA.
+
+
 import pcapy
 from impacket.ImpactDecoder import EthDecoder as Ethernet
 from threading import Thread
 import time
 import urllib
+from tuxisalive.lib.misc import urlTools
+from tuxisalive.lib.daemonizer import Daemonizer
 
+sniffing = False
+
 def searchForIfaces():
         try:
                 interfaces =  pcapy.findalldevs()
@@ -16,36 +41,32 @@
         return interfaces
 
 class sniffer(Thread):
-    def __init__(self, iface, packetSize, promiscuite, timeout, sniffing, 
debug):
+    def __init__(self, reader, ip, sniff):
+        global sniffing
         Thread.__init__(self)
-        self.iface = iface
-        self.packetSize= packetSize
-        self.promiscuite = promiscuite
-        self.timeout = timeout
-        self.sniffing = sniffing
-        self.reader = pcapy.open_live(self.iface,
-                self.packetSize,
-                self.promiscuite,
-                self.timeout)
-        self.DEBUG = debug
-
-        if self.DEBUG:
-            print(self.iface + " : " + self.reader.getnet() + " : " + 
self.reader.getmask() )
+        self.ip = ip
+        self.reader = reader
+        sniffing = sniff
+        
+        self.MSN_MSG_REQ = 
"http://127.0.0.1:270/0/status/send?name=chatter&value=MSN|MSG|Nickname|%s";
                
     def run(self):
-        while self.sniffing:
+        global sniffing
+        while sniffing:
             try :
                 ethernet = Ethernet().decode(self.reader.next()[1])
                 ip = ethernet.child()
                 l4 = ip.child()
                 hl = l4.child()
                 text = hl.get_buffer_as_string()
-
-                if self.DEBUG:
-                    print( "IP src : " + str(ip.get_ip_src()))
-                    print( "IP dst : " + str(ip.get_ip_dst()))
-                    print( "layer4 : " + str(self.layer4(l4)))
-                    print(hl.get_buffer_as_string())
+                if str(ip.get_ip_src()).find(self.ip) != 0 and \
+                        text.find("MSG") == 0:
+                    text = text.split("\n")[5]
+                    text = text.replace(" ", "%20")
+                    text = text.replace("|", "§§§§§£")
+                    text = text.replace("&", "§§§§£")
+                    text = text.replace("+", "§§§£")
+                    urlTools.urllib2.urlopen(self.MSN_MSG_REQ %text)
             except:
                 pass                                       
                                      
@@ -60,9 +81,15 @@
        
 if __name__ == '__main__':
     def run():
+        while urlTools.getUrlInfo("http://www.google.com";)[0] == False:
+            time.sleep(1)
         for iface in searchForIfaces() :
-            sniffIface = sniffer(iface, 1024, 0, 100, True, False)
-            sniffIface.start()
-    from tuxisalive.lib.daemonizer import Daemonizer
-    tuxHttpDaemon = Daemonizer('chattertux', '/var/log', run, True)
-    tuxHttpDaemon.start()
+            reader = pcapy.open_live(iface, 1024, 0, 100)
+            ip = (reader.getnet().split("."))
+            ip=str(ip[0])+"."+str(ip[1])
+            if ip != "0.0":
+                sniffIface = sniffer(reader, ip, True)
+                sniffIface.start()
+
+    chatterTuxDaemon = Daemonizer('chattertux', '/var/log', run, True)
+    chatterTuxDaemon.start()


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Tux-droid-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tux-droid-svn

Reply via email to