- #!/usr/bin/python
- import socket
- from Tkinter import *
- import sys
-
- #AUTEUR : karim boumedhel
- #LICENCE :
- #use it and enjoy
-
- # VERSION : 0.1 / 09 mai 2006
- #this is a basic client/server popup messenger
- #which is launched by python tkpopup -c in client mode(to send a popup message)
- #or python tkpopup.py -s to wait for incoming
- #please note you end your message with a double dot
- #and you shutdown the server by sending him the string $$$ locally (which u can achieve via tkpopup.py client or by netcat or telnet or whatever....:)
- #stupid "bug" to fix : if u send a line with .. and with other stuff,ur message is ended(yeah that s really stupid , i ll fix that later....
-
- #ask user for default port and interface....
- #the port on which we ll be listening on the other side
- #adjust to the settings u need (on unix platforms)
- #default_listening_port=8083
- #default_interface="192.168.3.2"
- #default_sending_port=8083
-
- def send_message(text,address):
- s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
- try:
- s.connect((address,default_sending_port))
- except socket.error:
- print "there was an error ,maybe we cant reach this address"
- sys.exit()
- try:
- banner=s.recv(1024)
- print banner
- if banner !="22 tkpopup server ready\n":
- print "we re not connecting to a tkpopserver server,leaving"
- sys.exit()
-
- except:
- print "no response"
- sys.exit()
- #finally send the message
- s.send(text)
-
- if len(sys.argv) != 2 :
- print "Usage:tkpopup -s or tkpopup -c"
- sys.exit()
- elif not sys.argv[1] in ["-s","-c"] :
- print "usage:tkpopup -s or tkpopup -c"
- sys.exit()
-
-
-
- if sys.argv[1]=="-s":
- #we re running in server mode
- #ask for parameters
- #we ll ask only on win platform:
- if sys.platform=="win32":
- default_listening_port=int(raw_input("enter default_port:"))
- default_interface=raw_input("enter default_interface:")
- s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
- try:
- s.bind((default_interface,default_listening_port))
- except:
- print
- s.listen(5)
- print "listening on default port "+str(default_listening_port)
- while True:
- conn,recv=s.accept()
- print "connection from "+recv[0]
- conn.send("22 tkpopup server ready\n")
- textos=conn.recv(5120)
-
- if textos[:3]=="$$$" and recv[0]==default_interface:
- conn.send("shuting down server...")
- conn.close()
- print "received closing sequence..."
- s.close()
- sys.exit()
- conn.close()
- print "message delivered"
- try:
- root=Tk()
- w=Label(root, text=textos)
- w.pack()
- root.mainloop()
- except:
- print "cant get display,so here s the message"
- print textos
-
- if sys.argv[1]=="-c":
- #we re running in client mode,ie we re sending a message
- if sys.platform=="win32":
- default_sending_port=int(raw_input("enter default_sending_port:"))
- text=raw_input("enter text to send,and end with double dot\n")+"\n"
- while text[-3:] !="..\n":
- text += raw_input()+"\n"
- text=text[:-2]
-
- address=raw_input("enter destination ip....\n")
- send_message(text,address)
-
-
-
-
#!/usr/bin/python
import socket
from Tkinter import *
import sys
#AUTEUR : karim boumedhel
#LICENCE :
#use it and enjoy
# VERSION : 0.1 / 09 mai 2006
#this is a basic client/server popup messenger
#which is launched by python tkpopup -c in client mode(to send a popup message)
#or python tkpopup.py -s to wait for incoming
#please note you end your message with a double dot
#and you shutdown the server by sending him the string $$$ locally (which u can achieve via tkpopup.py client or by netcat or telnet or whatever....:)
#stupid "bug" to fix : if u send a line with .. and with other stuff,ur message is ended(yeah that s really stupid , i ll fix that later....
#ask user for default port and interface....
#the port on which we ll be listening on the other side
#adjust to the settings u need (on unix platforms)
#default_listening_port=8083
#default_interface="192.168.3.2"
#default_sending_port=8083
def send_message(text,address):
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
try:
s.connect((address,default_sending_port))
except socket.error:
print "there was an error ,maybe we cant reach this address"
sys.exit()
try:
banner=s.recv(1024)
print banner
if banner !="22 tkpopup server ready\n":
print "we re not connecting to a tkpopserver server,leaving"
sys.exit()
except:
print "no response"
sys.exit()
#finally send the message
s.send(text)
if len(sys.argv) != 2 :
print "Usage:tkpopup -s or tkpopup -c"
sys.exit()
elif not sys.argv[1] in ["-s","-c"] :
print "usage:tkpopup -s or tkpopup -c"
sys.exit()
if sys.argv[1]=="-s":
#we re running in server mode
#ask for parameters
#we ll ask only on win platform:
if sys.platform=="win32":
default_listening_port=int(raw_input("enter default_port:"))
default_interface=raw_input("enter default_interface:")
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
try:
s.bind((default_interface,default_listening_port))
except:
print
s.listen(5)
print "listening on default port "+str(default_listening_port)
while True:
conn,recv=s.accept()
print "connection from "+recv[0]
conn.send("22 tkpopup server ready\n")
textos=conn.recv(5120)
if textos[:3]=="$$$" and recv[0]==default_interface:
conn.send("shuting down server...")
conn.close()
print "received closing sequence..."
s.close()
sys.exit()
conn.close()
print "message delivered"
try:
root=Tk()
w=Label(root, text=textos)
w.pack()
root.mainloop()
except:
print "cant get display,so here s the message"
print textos
if sys.argv[1]=="-c":
#we re running in client mode,ie we re sending a message
if sys.platform=="win32":
default_sending_port=int(raw_input("enter default_sending_port:"))
text=raw_input("enter text to send,and end with double dot\n")+"\n"
while text[-3:] !="..\n":
text += raw_input()+"\n"
text=text[:-2]
address=raw_input("enter destination ip....\n")
send_message(text,address)