mirror of
https://github.com/krislamo/Flea
synced 2024-12-16 11:10:34 +00:00
Connect to an IRC server
Added a basic SSL connection; simplified Flea.py file
This commit is contained in:
parent
00db7f073e
commit
1b3c78dd2a
3
Flea.py
3
Flea.py
@ -17,8 +17,7 @@
|
|||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from core.main import *
|
import core.main
|
||||||
main()
|
|
||||||
except:
|
except:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
input()
|
input()
|
||||||
|
46
core/main.py
46
core/main.py
@ -15,8 +15,52 @@
|
|||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>
|
# along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||||
|
|
||||||
from core.config import *
|
from core.config import *
|
||||||
|
import socket
|
||||||
|
import ssl
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
config = cfgParser("settings.conf")
|
config = cfgParser("settings.conf")
|
||||||
print "config = "+repr(config)
|
|
||||||
|
# Create socket object
|
||||||
|
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
|
sock.settimeout(10)
|
||||||
|
|
||||||
|
# Wrap socket object to create SSLSocket object
|
||||||
|
sock = ssl.wrap_socket(sock)
|
||||||
|
|
||||||
|
# Connect to IRC server
|
||||||
|
sock.connect((config["host"], config["port"]))
|
||||||
|
print "Connecting to "+config["host"]+':'+str(config["port"])
|
||||||
|
|
||||||
|
# Display SSL information to the user
|
||||||
|
ssl_info = sock.cipher()
|
||||||
|
if ssl_info != None:
|
||||||
|
print "[SSL] Cipher: "+ssl_info[0]
|
||||||
|
print "[SSL] Version: "+ssl_info[1]
|
||||||
|
print "[SSL] Bits: "+str(ssl_info[2])
|
||||||
|
|
||||||
|
while True:
|
||||||
|
# Buffer to store data from server
|
||||||
|
data = ''
|
||||||
|
|
||||||
|
while True:
|
||||||
|
# Receive data from connection
|
||||||
|
tmpdata = sock.recv(4096)
|
||||||
|
data = data + tmpdata
|
||||||
|
|
||||||
|
if len(tmpdata) < 4096:
|
||||||
|
break
|
||||||
|
|
||||||
|
# If no incoming data exists then connection has closed
|
||||||
|
if len(tmpdata) == 0:
|
||||||
|
input("Connection closed.")
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
# Split data to easily deal with it
|
||||||
|
data = tmpdata.split("\r\n")
|
||||||
|
for line in data:
|
||||||
|
if len(line) > 0:
|
||||||
|
print line
|
||||||
|
|
||||||
|
main()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user