def route_info(): return { 'success': True, 'version': { 'curl': curl_version, 'trino': trino.vercheck() }, 'network': { 'pieces': nslookup(), 'trino': trino.ipcheck() } }
def update_gui(option, obj): try: if option == 0: tmp = obj.ping.tmp.text() + "\n" obj.ping.tmp.setText(tmp + ping(obj.ping.field.text())[0]) if option == 1: tmp = obj.trace.tmp.text() + "\n" obj.trace.tmp.setText(tmp + trace(obj.trace.field.text())) if option == 2: tmp = obj.dns.tmp.text() + "\n" obj.dns.tmp.setText(tmp + nslookup(obj.dns.field.text())) except Exception: msg = QMessageBox() msg.setIcon(QMessageBox.Critical) msg.setText( "Error! \n\n-Make Sure you entered correct dst. \n-Make sure you have admin permissions." ) msg.setWindowTitle("Error") msg.exec_()
def main(args): # Establish IPv4 address if not is_valid_ip(args.host): if is_valid_hostname(args.host): args.host = nslookup(args.host) else: raise IOError(f'Could not parse argument \'host\': {args.host}') print(args.host) # Trace the route if True: # FIXME traceroute_output = traceroute(args.host) ips = [l.ip for l in traceroute_output if l.ip is not None] else: ips = [ '192.168.1.1', '50.53.152.1', '50.46.177.146', '50.46.176.48', '204.194.220.5', '107.191.236.64', '206.81.80.112', '202.158.194.120', '113.197.15.146', '113.197.15.12', '113.197.15.11', '138.44.161.3', '150.203.201.5', '150.203.201.33', '130.56.66.152' ] if True: # FIXME from pprint import pprint pprint(ips) # Write to map print('Generating map:') map_ = Map() coords_prev = None connect = [] from map import Color # FIXME for ip in ips: whois_output = whois(ip) coords = get_most_precise_location(whois_output) if coords is None: print('-->', 'No location found. Skipping', ip) continue if coords == coords_prev: print('-->', 'Same location. Omitting', ip) continue map_.add_route_point(coords, color=Color.blue) # if coords_prev is not None: # map_.add_route_segment(coords_prev, coords) connect.append(coords) coords_prev = coords for i in range(len(connect) - 1): map_.add_route_segment(connect[i], connect[i + 1]) map_.save() exit(0) whois_output = whois(args.host) coords_endpoint = get_most_precise_location(whois_output) print(f'Endpoint location: {coords_endpoint}')
def command_loop(): while True: try: data = getData() with open("bert.log", "a") as f: f.write(data) f.close() ircmsg = data.strip("\n\r") if ircmsg.find("PING :") != -1: pingstring = ircmsg.strip("PING :") ping(pingstring) if ircmsg.find("ERROR :Closing link") != -1: print("Error. Lost Connection. Giving up!") os._exit(1) break if ircmsg.find(" PRIVMSG ") != -1: ircnick = ircmsg.split("!")[0][1:] channel = ircmsg.split(" PRIVMSG ", 1)[-1].split(" :", 1)[0] msg = ircmsg.split(channel+" :", 1)[1] if channel == nick: print("direct message received") if msg == "\x01VERSION\x01": print("got ctcp version request") notice(ircnick, "\x01VERSION BertBot "+version+"\x01") elif msg.startswith("\x01PING"): print("got ctcp ping request") pingstring = msg.split()[1] notice(ircnick, "\x01PING "+pingstring+"\x01") continue if msg == ".hello": say(channel, "Hello "+ircnick) elif msg == ".help": print("sending help") say(channel, "available commands: .nextrocket, .slap, .mate, .jn, .rep, .twitter, .trump, .konfuzius, .fml, .eurusd, .usdeur, .nslookup") elif msg == ".nextrocket": try: print("found Rocket command\nRequesting next rocketlaunch...") response = getRocket() say(channel, response) except: print("Error getting next rocketlaunch") say(channel, "Error contacting LaunchLibrary API") elif msg.startswith(".slap"): try: slapname = msg.split()[1] print("slapping "+slapname) say(channel, ircnick+" slaps "+slapname+" around a bit with a large trout") except Exception as err: print(err) elif msg.startswith(".mate"): try: try: user = msg.split()[1] print("schenke mate an "+user+" aus") me(channel, "reicht "+user+" eine eiskalte Mate. Prost du scheiss Hipster.") except: print("schenke mate an "+ircnick+" aus") me(channel, "reicht "+ircnick+" eine eiskalte Mate. Prost du scheiss Hipster.") except Exception as err: print(err) elif msg.startswith(".eurusd"): try: value = float(msg.split()[1]) rate = calc_currency("eur", value) say(channel, "USD: {0:.2f}".format(rate)) except Exception as err: say(channel, "could not get data") print(err) elif msg.startswith(".usdeur"): try: value = float(msg.split()[1]) rate = calc_currency("usd", value) say(channel, "EUR: {0:.2f}".format(rate)) except Exception as err: say(channel, "could not get data") print(err) elif msg.startswith(".jn"): choose = yon() try: print("choose "+choose+" for "+ircnick) if choose == "y": say(channel, ircnick+": "+g+"Ja") else: say(channel, ircnick+": "+r+"Nein") except Exception as err: print(err) elif msg.startswith(".rep"): try: user = msg.split(" ", 2)[1] print("got rep message from "+str(ircnick)+" for "+str(user)) try: reason = msg.split(" ", 2)[2] print("with reason "+str(reason)) except: reason = "None" print("with no reason") if user == ircnick: say(channel, "You can't give rep to yourself. Selfish little prick!") continue try: acc_name = is_registered(user) give_acc = is_registered(ircnick) print("found account name for "+str(user)+": "+str(acc_name)) if acc_name != None and give_acc != None: give_rep(acc_name, user, give_acc, reason, channel) elif give_acc == None: say(channel, "You are not registered!") continue else: say(channel, "invalid or not registered user") continue except Exception as err: print("Error in giving rep! - "+str(err)) except Exception as err: print("No rep user found! - "+str(err)) try: acc_name = is_registered(ircnick) if acc_name != None: rep_result = get_rep(acc_name) rep = rep_result[0] reason = rep_result[1] say(channel, "Your reputation: "+str(rep)+" - Last reason: "+str(reason)) else: say(channel, "You are not registered") continue except Exception as err: print("Error getting rep! - "+str(err)) elif msg.startswith(".twitter"): try: twittername = msg.split()[1] try: lasttweet = api.user_timeline(screen_name=twittername, count=1, tweet_mode="extended")[0] twit = lasttweet.full_text user = lasttweet.user.name text = html.unescape(re.sub(r'\n', ' ', twit)) say(channel, b+user+": "+c+text) except Exception as err: print("Could not get last tweet! "+err) except: say(channel, "You have to give me a username") elif msg.startswith(".trump"): try: twittername = "realdonaldtrump" lasttweet = api.user_timeline(screen_name=twittername, count=1, tweet_mode="extended")[0] twit = lasttweet.full_text user = lasttweet.user.name text = html.unescape(re.sub(r'\n', ' ', twit)) say(channel, b+user+": "+c+text) except Exception as err: print("Could not get last tweet! "+err) elif msg.startswith(".konfuzius"): try: quote = konfuzius.random_quote() say(channel, b+"Konfuzius sagt: "+c+quote) except: say(channel, "Error :(") elif msg == ".quit": if ircnick == "elmo": say(channel, "Flying to mars...") print("got quit command. exiting...") part(channel) safeexit() else: say(channel, "You are not my master!") elif msg.startswith(".say"): if ircnick == "elmo": try: sayit = msg.split(" ", 1)[1] say(channel, str(sayit)) except: say(channel, "What should I say?") continue else: say(channel, "You are not my master!") elif msg.startswith(".debug"): if ircnick == "elmo": try: debugmsg = msg.split(" ", 1)[1] raw(debugmsg) except: say(channel, "What should I say?") continue else: say(channel, "You are not my master!") elif "twitter.com" in msg: try: p = re.compile('twitter\.com/[A-Za-z0-9]*/status/[0-9]*') tweet_link = p.search(msg).group(0) status_id = tweet_link.split("/")[3] status = api.get_status(status_id, tweet_mode="extended") user = status.user.name text = status.full_text print("found twitter link\n"+user+" - "+text) say(channel, b+user+": "+c+text) except Exception as err: print("twitter link invalid "+str(err)) elif urlinfo.is_url(msg) != None: try: url = urlinfo.is_url(msg) ignore = ["pr0gramm", "w0bm", "f0ck", "twitter", "youtube", "youtu.be"] if any(ign in url for ign in ignore): pass else: title = urlinfo.get_title(url) print("Found URL and got title "+str(title)) say(channel, b+"Title: "+c+title) except Exception as err: print("Error getting URL title - "+str(err)) elif msg == ".fml": try: fml_string = fml.get_fml(fml_url) print("got fml command") say(channel, c+fml_string+b+" FML.") except Exception as err: print("Error getting URL title "+str(err)) elif msg.startswith(".nslookup"): try: msg_parts = msg.split(" ") try: nsdomain = msg_parts[1] except: say(channel, r+"You must specify a domain!") continue try: nstype = msg_parts[2] except: nstype = "A" print("got nslookup command with domain: "+str(nsdomain)+" and type: "+str(nstype)) nsresult = nslookup(nsdomain, nstype) nslines = nsresult.split("\n") for nsline in nslines: say(channel, y+" "+str(nsline)) except Exception as err: print("Error in nslookup - "+str(err)) #elif "i won't" in msg: # try: # say(channel, "blp") # except Exception as err: # print("could not blp - "+str(err)) except Exception as err: print(err)
def ipcheck(self): if self.__ip is not None: return self.__ip results = [nslookup(agent.host) for agent in self.agents] self.__ip = self.as_dict(lambda agent: agent.host, results) return self.__ip