Sinisterly
Maya Networking Tool - Printable Version

+- Sinisterly (https://sinister.ly)
+-- Forum: Coding (https://sinister.ly/Forum-Coding)
+--- Forum: Python (https://sinister.ly/Forum-Python)
+--- Thread: Maya Networking Tool (/Thread-Maya-Networking-Tool)



Maya Networking Tool - Inori - 12-31-2015

I got bored, learned about sockets and JSON tricks, and made this. I'm too tired to outline everything, so there's tips and everything in the help command.

Running (since this apparently confuses people):
Code:
#from parent directory
$ python maya
#from source directory
$ python .

Files:

__main__.py:
Code:
from subprocess import call
import portscanner
import geoip

header=''' __  __   ___ __   __ ___  
|  \/  | / _ \\\\ \ / // _ \
| .  . |/ /_\ \\\\ V // /_\ \\
| |\/| ||  _  | \ / |  _  |
| |  | || | | | | | | | | |
\_|  |_/\_| |_/ \_/ \_| |_/
'''+'*'*27
services={'notes': ['leave ip/host field blank for current host','hit enter after service to return to menu'],'port scanner': ['id           : 2','desc         : scans specified host for open ports in range','instructions : follow prompts','source       : portscanner.py'],'ip locator': ['id           : 1','desc         : geolocates IPs using https://freegeoips.net/','instructions : follow prompts','source       : geoip.py']}

def main():
    call('clear',shell=True)
    print header
    i=raw_input('Enter service ID (0 for service help): ')
    try: title=['help','port scanner','ip locator'][int(i)]
    except: main()
    print title+'\n'+'-'*len(title)
    if int(i)==0:
        for (k,v) in services.iteritems():
            print k
            for x in v: print '    '+x
    elif int(i)==1: portscanner.scanner()
    elif int(i)==2: geoip.getgeo()
    raw_input()
    main()

main()

geoip.py:
Code:
from requests import get

def getgeo():
    ip=raw_input('Enter ip or hostname to locate: ')
    if ip=='': ip=get('https://api.ipify.org').content
    for (k,v) in eval(get('https://freegeoip.net/json/'+ip).content).iteritems():
        print '{:<13}: {}'.format(k.replace('_',' ').title(),v)

portscanner.py:
Code:
from datetime import datetime
from threading import Thread
from requests import get
import socket

def scanner():
    serv=socket.gethostbyname(raw_input('Enter host to scan: '))
    if serv=='': serv='0.0.0.0'
    r=map(int,raw_input('Enter port range: ').split(' '))
    r=range(r[0],r[-1]+1)
    grps=[r[i:i+3] for i in range(0,r[-1],3)]
    def scan(serv,g):
        try:
            for port in g:
                sock=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
                s=sock.connect_ex((serv,port))
                if s==0: print "Port ["+str(port)+"]: "+"Open"
                sock.close()
        except socket.gaierror:
            print 'Hostname could not be resolved. Exiting'
            exit()
        except socket.error:
            print "Couldn't connect to server"
            exit()
        except KeyboardInterrupt:
            exit()
    time=datetime.now()
    for g in grps:
        if g!=[]:
            t=Thread(target=scan,args=(serv,g))
            t.start()
            t.join()
    print "finished scanning",serv,"in",str(datetime.now()-time)[:-4]



RE: Maya Networking Tool - zorrophreak - 12-31-2015

Interesting. I'll check it out when I get back to my linux box. Python on Windows is Cancerous


RE: Maya Networking Tool - Inori - 12-31-2015

(12-31-2015, 08:39 AM)zorrophreak Wrote: Interesting. I'll check it out when I get back to my linux box. Python on Windows is Cancerous

I actually made it on winblows to make sure that it's cross-compatible, so cancer away Tongue


RE: Maya Networking Tool - Nil - 01-01-2016

(12-31-2015, 08:39 AM)zorrophreak Wrote: Interesting. I'll check it out when I get back to my linux box. Python on Windows is Cancerous

Lol, what makes python on Windows cancerous? I've never had any issues with anything before.

Thanks Nevermore.