How to create your own private and encrypted chat server – neuron python script 2016

 Here in 2016 we have tons and tons of chat application with various features. They have millions of users and giant servers at very high speed but still why hackers and geeks are running behind encrypted communication like torchat? because privacy. Even though you are using an encrypted and secured application, keep in mind still they work on a third party server you cannot trust them blindly. They can be broken any time. If you are really concerned about privacy, here i have developed a simple application NEURON in python.

Neuron server can be setup on your linux machine and have full controll over it. Neuron python sockets to send message with AES encryption. It has two scripts basically one as server and other as client. Set up server on any machine so that your firends with the script can connect to your server remotely with the correct password. No one can invade your privacy, if you find any malicious activity you can simply shut down the server. You can see the connections on the server console and even live chat if you changed the view mode. This is safe application because messages are encrypted in AES algorithm which cannot be cracked without the right key. If an eavesdropper tries to sneak in with a wrong password and if we send a message his script decrypt it with a different key i.e. even if he got the messages in this format he cannot decrypt to raw strings.

This server don’t have any special hardware requirements this can be run on any linux machine and can be user on both LAN and WAN network. Neuron is available on github, follow the steps for complete tutorial. check out the video too so that it will give you an idea.NOTE: forward the port on router for remote connections over internet.

Demo video


Download neuron

clone to github
# git clone


Setup server

Now open the folder so that you can find two main python script and a config file. Config file is for server script, you can tweak it. Open the file with any text editor change the HOST to your internal IP if you are using it on lan network. Change HOST to your public ip if you are using it on WAN network. PORT can be any unused port. Option PASSWORD can be any desired password. change view mode to 1 if you want live feed of chat on the server console. Save and close the file and right click open terminal on that directory.

# python usage

Once the server is setup only thing you need is . Anyone with your host details and correct password can connect to your server and create a group chat. Open the terminal in the directory and use the command below.
# python “host_ip” “port” “password” “nick_name”

all your friends can connect from the internet with this simple piece of script.

Any doubts or questions? post it on the comment section below. If you like this blog give me a like on facebook and add me on google plus. Subscribe my youtube channel for video tutorials.


susmith HCK

susmith HCK

I’m a computer enthusiast basically and i love to write blogs on tech issues and cyber security. I started penetration testing at the age of 16 and i would like to explore security vulnerabilities and latest tech news and wanna share with you. If you like all these stuffs add me on Facebook and Google plus.

You may also like...

41 Responses

  1. 1Ztw.Cn says:

    Wonderful goods from you, man. I have understand
    your stuff previous to and you are just too excellent.

    I really like what you have acquired here, really like what you’re saying and the way in which you say it.
    You make it enjoyable and you still care for to keep it wise.
    I cant wait to read far more from you. This is actually a terrific web site.

  2. Fine wayy of telling,and pleasant paragraph to obyain information about my presentatikn subject matter, which i
    am going to deliver in academy.

  3. It is not my first time to pay a quick visit this website, i am
    visiting this website dailly and get fastidious facts from
    here all the time.

  4. Robin says:

    Have you ever considered writing an e-book or guest authoring on other sites?

    I have a blog centered on the same topics you discuss and would love to have
    you share some stories/information. I know my visitors would appreciate your work.
    If you’re even remotely interested, feel free to
    send me an email.

  5. Very shortly this web page will be famous amid all blog
    users, due to it’s good posts

  6. Hi there mates, its great article on the topic of educationand completely explained, keep it up all
    the time.

  7. Bernie says:

    Great article, exactly what I needed.

  8. Elva says:

    It is appropriate time to make a few plans for the long run and it is time
    to be happy. I’ve learn this publish and if I could I want
    to counsel you few fascinating things or tips. Perhaps you could write next articles regarding this article.
    I want to learn even more things approximately it!

  9. Barney says:

    When I originally commented I clicked the “Notify me when new comments are added” checkbox and now each time
    a comment is added I get three e-mails with the same comment.
    Is there any way you can remove people from that service?

    Many thanks!

  10. Greetings! Very useful advice within this post!

    It is the little changes that make the most important changes.
    Many thanks for sharing!

  11. Appreciate the recommendation. Will try it out.

  12. Cool blog! Is your theme custom made or did you download it
    from somewhere? A design like yours with a few simple adjustements
    would really make my blog shine. Please let me know where you got your theme.
    Many thanks

  13. Hello! I just would like to offer you a huge thumbs up for
    your great information you have got here on this post. I’ll be coming back to your site for more soon.

  14. Beverly says:

    I really like it when people get together and share ideas.

    Great website, stick with it!

  15. Finlay says:

    Hello there! Nice post! Please keep us posted!

  16. Fantastic blog you have here but I was curious about if you
    knew of any message boards that cover the same topics discussed in this article?
    I’d really love to be a part of community where I can get comments
    from other knowledgeable people that share the same interest.
    If you have any recommendations, please let
    me know. Appreciate it!

  17. Drew says:

    It’s nearly impossible to find experienced people on this
    topic, but you sound like you know what you’re talking about!

  18. Hi! I simply want to offer you a huge thumbs up for your
    excellent info you have got right here on this post. I will be returning to your blog for more soon.

  19. Vince says:

    Pretty great post. I simply stumbled upon your weblog and wished to mention that I have really enjoyed
    browsing your blog posts. After all I will be
    subscribing for your rss feed and I’m hoping you write once
    more soon!

  20. Greg says:

    Howdy! I simply want to give you a big thumbs
    up for the great info you have got right here on this post.
    I’ll be coming back to your blog for more soon.

  21. This page certainly has all of the info I wanted
    about this subject and didn’t know who to ask.

  22. But the host ip of clients are visible and can be monitored… if you can add a network cryptography module…

    • U mean hiding client ip ? IP is the basic protocol, we cannot simply encrypt and communicate. However we can use tor . That would be better idea. I will think about it.. 😀 if u are coder u can modify the code and commit on github .

  23. Arch!m3de says:

    Hi, I have a little problem. I configure the neuron.conf to use neuron over the internet. So, i put my public ip. But, when i launch python i get the error:
    socket.error: [Errno 99] Cannot assign requested address

    Can you explain, if it’s possible, how to fix it ? 🙂


    • you cannot assign public ip in the server, but you can use internal ip and then forward the port in router. Just enter the external ip in the client. you can connect remotely.

  24. CyberEnginner says:

    Hello there sir! great article as always 🙂
    But i have a question if you don’t mind ! i want to know how to host this kind of project in a external server so it could stay always online.

    I’ve read the previews comment and i understood you answer, but if i host the server on one of my devices that device must be always turned on in order to keep the server always online !!! and i’m afraid that this is impossible because i can’t keep my laptop 24/7 on.

    So i’m looking for something that like VPS or Python Server like or any host that can run the nueron server and be online 24/7 just like websites do.

    I really hope that you respond sir as soon as possible because i’m really exited about it, besides your respond will open a new door of future opportunities in the hosting field…and thank you in advance 🙂

  25. john says:

    hello was a great program..
    but if you make a tutorial for explaining how the code work, that will be fantastic

  26. sahiltikoo says:

    hey buddy i am having some problem with the aes encrypted chat i developed could you please look at it , , basically when the message is broadcasted that any user has joined the chatroom an error pops up that input string must be multiple of 16 . I am from india and nobody know anything about python scripting in my college , please help!!

  27. B4D51573M says:

    Traceback (most recent call last):
    File “”, line 126, in
    File “”, line 69, in chat_server
    server_socket.bind((HOST, PORT))
    File “/usr/lib/python2.7/”, line 228, in meth
    return getattr(self._sock,name)(*args)
    socket.error: [Errno 99] Cannot assign requested address
    How I fix this?

  28. chris says:

    Hey lads! i followed this great tutorial but i ran into small problems,the coding didn’t work on my windows op i changed couple things to make it run but when i connected to my chat i couldn’t type, non of my keys on keyboard worked could you guys help me out please>? 🙂

    # neuron_client

    import base64
    import sys, socket, select
    from Crypto.Cipher import AES
    import os
    import hashlib
    import signal

    print “””
    ___ ___ __ _________ ___
    / _ \/ -_) // / __/ _ \/ _ \
    /_//_/\__/\_,_/_/ \___/_//_/
    messenger v 1.2 | susmithHCK


    def sigint_handler(signum, frame):
    print ‘\n user interrupt ! shutting down’
    print “[info] shutting down NEURON \n\n”

    signal.signal(signal.SIGINT, sigint_handler)

    def hasher(key):
    hash_object = hashlib.sha512(key)
    hexd = hash_object.hexdigest()
    hash_object = hashlib.md5(hexd)
    hex_dig = hash_object.hexdigest()
    return hex_dig

    def encrypt(secret,data):
    BLOCK_SIZE = 32
    PADDING = ‘{‘
    pad = lambda s: s + (BLOCK_SIZE – len(s) % BLOCK_SIZE) * PADDING
    EncodeAES = lambda c, s: base64.b64encode(c.encrypt(pad(s)))
    cipher =
    encoded = EncodeAES(cipher, data)
    return encoded

    def decrypt(secret,data):
    BLOCK_SIZE = 32
    PADDING = ‘{‘
    pad = lambda s: s + (BLOCK_SIZE – len(s) % BLOCK_SIZE) * PADDING
    DecodeAES = lambda c, e: c.decrypt(base64.b64decode(e)).rstrip(PADDING)
    cipher =
    decoded = DecodeAES(cipher, data)
    return decoded

    def chat_client():
    if(len(sys.argv) < 5) :
    print 'Usage : python ‘

    host = sys.argv[1]
    port = int(sys.argv[2])
    key = sys.argv[3]
    key = hasher(key)
    uname = sys.argv[4]

    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

    try :
    s.connect((host, port))

    except :
    print “\033[91m”+’Unable to connect’+”\033[0m”

    print “Connected to remote host. You can start sending messages”
    sys.stdout.write(“\033[34m”+’\n[Me :] ‘+ “\033[0m”); sys.stdout.flush()

    while 1:
    socket_list = [socket.socket(), s]
    read_sockets, write_sockets, error_sockets = , [], [])

    for sock in read_sockets:
    if sock == s:

    data = sock.recv(4096)

    if not data :
    print “\033[91m”+”\nDisconnected from chat server”+”\033[0m”
    else :
    data = decrypt(key,data)
    sys.stdout.write(“\033[34m”+’\n[Me :] ‘+ “\033[0m”); sys.stdout.flush()

    else :

    msg = socket.socket().readline()
    msg = ‘[ ‘+ uname +’: ] ‘+msg
    msg = encrypt(key,msg)
    sys.stdout.write(“\033[34m”+’\n[Me :] ‘+ “\033[0m”); sys.stdout.flush()

    if __name__ == “__main__”:


Leave a Reply

Your email address will not be published. Required fields are marked *