def localDnsServer(): localDnsServerSocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # try: localDnsServerSocket.bind((LOCAL_HOST, LOCAL_DNS_SERVER_PORT)) print( f"localDNS is up and running and I am listening at Port:{LOCAL_DNS_SERVER_PORT}") while True: clientMessage, clientAddress = localDnsServerSocket.recvfrom( BUFFER_SIZE) userInput = clientMessage.decode() print(f"Talking to the Client at the Address:{clientAddress}") print(f"Client Message:{userInput}") message = f"Hang in there client, I will get the IP Address of the \"{userInput}\"" message = message.encode() localDnsServerSocket.sendto(message, clientAddress) defaultResolver = dns.resolver.get_default_resolver() rootNameServer = defaultResolver.nameservers[0] splitResult = splitInput(userInput) splitResult.reverse() rootInput, tldInput, *_ = splitResult tldInput = tldInput + "." + rootInput authoritativeInput = getInput(userInput, len(splitResult)) authoritativeInput = authoritativeInput[:-1] customPrint("rootInput", rootInput) customPrint("tldInput", tldInput) customPrint("_", _) customPrint("authoritativeInput", authoritativeInput) if bool(cache) and rootInput in cache: tldNameServer = fetchFromCache(rootInput) else: rootMessage = "Root Result" tldNameServer = generalServerHandler( userInput, rootNameServer, ROOT_SERVER_PORT, rootMessage) cache[rootInput] = tldNameServer tldMessage = "TLD Result" authoritativeServer = generalServerHandler( userInput, tldNameServer, TLD_SERVER_PORT, tldMessage) cache[tldInput] = authoritativeServer authoritativeMessage = "Authoritative Result" finalIpAddress = generalServerHandler( userInput, authoritativeServer, AUTHORITATIVE_SERVER_PORT, authoritativeMessage) cache[authoritativeInput] = finalIpAddress customPrint("cache", cache) print() print(f"Final IP Address : {finalIpAddress}") print() serverMessage = finalIpAddress.encode() localDnsServerSocket.sendto(serverMessage, clientAddress)
def findOutAuthoritative(userInput, nameServer): returnMessage = [] defaultResolver = dns.resolver.get_default_resolver() converToDomainName = dns.name.from_text(userInput) numberOfWords = 2 tldInput = getInput(userInput, numberOfWords) customPrint("Customized tldInput", tldInput) if len(splitInput(userInput)) > 2: message = f"I dont know the address \"{userInput}\" but I know the address of \"{tldInput}\"" returnMessage.append(message) returnMessage.append(f"Looking up \"{tldInput}\" on \"{nameServer}\"") query = dns.message.make_query(tldInput, dns.rdatatype.NS) response = dns.query.udp(query, nameServer) responseCode = response.rcode() if responseCode != dns.rcode.NOERROR: if responseCode == dns.rcode.NXDOMAIN: returnMessage.append(f"\"{tldInput}\" does not exist.") returnMessage.append("Please enter a legible domain") return returnMessage else: returnMessage.append("Please enter a legible domain.") return returnMessage resourceRecordSet = None if len(response.authority) > 0: resourceRecordSet = response.authority[0] else: resourceRecordSet = response.answer[0] resourceRecord = resourceRecordSet[0] if resourceRecord.rdtype == dns.rdatatype.SOA: returnMessage.append( f"Same server is authoritative for \"{tldInput}\"") else: authoritativeServerName = resourceRecord.target returnMessage.append( f"\"{authoritativeServerName}\" is authoritative for \"{tldInput}\"" ) warnings.filterwarnings("ignore", category=DeprecationWarning) ipAddressofAuthoritative = defaultResolver.query( authoritativeServerName).rrset[0].to_text() returnMessage.append( f"Ip Address of \"{authoritativeServerName}\" is \"{ipAddressofAuthoritative}\"" ) returnMessage.append(str(authoritativeServerName)) returnMessage.append(ipAddressofAuthoritative) return returnMessage
def findOutResultantIp(userInput, nameServer): returnMessage = [] defaultResolver = dns.resolver.get_default_resolver() converToDomainName = dns.name.from_text(userInput) numberOfWords = len(splitInput(userInput)) authoritativeInput = getInput(userInput, numberOfWords) customPrint("customized authoritativeInput", authoritativeInput) returnMessage.append( f"Looking up \"{authoritativeInput}\" on \"{nameServer}\"") query = dns.message.make_query(authoritativeInput, dns.rdatatype.A) response = dns.query.udp(query, nameServer) responseCode = response.rcode() if responseCode != dns.rcode.NOERROR: if responseCode == dns.rcode.NXDOMAIN: returnMessage.append(f"\"{authoritativeInput}\" does not exist.") returnMessage.append("Please enter a legible domain") return returnMessage else: returnMessage.append("Please enter a legible domain.") return returnMessage resourceRecordSet = None resourceRecord = "" if len(response.answer) > 0: resourceRecordSet = response.answer[0] resourceRecord = resourceRecordSet[0] if resourceRecord.rdtype != dns.rdatatype.A: returnMessage.append( f"\"{userInput}\" requires another Authoritative Server Call, fetching it directly" ) answer = dns.resolver.resolve(userInput, 'A') resourceRecord = answer[0] else: returnMessage.append( f"\"{userInput}\" requires another Authoritative Server Call, fetching it directly" ) answer = dns.resolver.resolve(userInput, 'A') resourceRecord = answer[0] finalIPAddress = str(resourceRecord) returnMessage.append( f"IP address of the \"{userInput}\" is \"{finalIPAddress}\"") returnMessage.append(finalIPAddress) return returnMessage
from selenium.webdriver.support import expected_conditions as EC # available since 2.26.0 driver = webdriver.Firefox() driver.get("http://localhost/otteny.com/cleanup/index.html") #OPTIONS timeOut = 20; fromP = random.randint(200, 900) toP = random.randint(901, 2000) #ASSING #inFrom.send_keys(From) #inCategory.select_by_visible_text(Category) #inNoStock.click() inputs = helpers.getInput(driver) inputs['inFromP'].send_keys(fromP) inputs['inToP'].send_keys(toP) inputs['inForm'].submit() try: WebDriverWait(driver, timeOut).until(EC.presence_of_element_located((By.ID,'product_link'))) count_span = driver.find_element_by_name("count") count_total = count_span.get_attribute("innerHTML") except ValueError: print "Oops! That was no valid number. Try again..." driver = helpers.restartDriver(driver) inputs = helpers.getInput(driver) inputs['inFromP'].send_keys(fromP) inputs['inToP'].send_keys(toP) inputs['inEnProducts'].click()
import pygal import talos import tensorflow as tf from keras.callbacks import ModelCheckpoint, TensorBoard from keras.layers import Conv2D, Dense, Dropout, Flatten, Lambda, MaxPooling2D from keras.models import Sequential from keras.optimizers import Adam from keras.utils import plot_model import helpers from helpers import INPUT_SHAPE gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=0.333) sess = tf.Session(config=tf.ConfigProto(gpu_options=gpu_options)) dataset_dir_name, checkpoint_dir_name, stats_dir_name, model_name = helpers.getInput( ) data = helpers.calibrate(dataset_dir_name) training_data, testing_data = helpers.getData(data, 75) trainingImages = helpers.getMatrix(training_data) testingImages = helpers.getMatrix(testing_data) print("_" * 40) print("Image translation to matrix completed") print("_" * 40) now = datetime.now() date_time = now.strftime("%m/%d/%Y, %H:%M:%S") # NAME = f"{model_name}_{date_time}"
for i in list_of_files: nb = int(i[len(result_name):-4]) list_of_numbers.append(nb) #if len(list_of_numbers)==0: # new_file_number = 1 #else: # new_file_number = np.max(list_of_numbers)+1 #info = {'ID':[new_file_number]} os.chdir(maindir) # get user data before setup, since Dlg does not work in fullscreen # can be used to ask for any input that is needed title = 'IAT window' #questions = {'ID': '', 'Condition': ['A', 'B']} questions = {'ID': ''} info = helpers.getInput(title, questions) or core.quit() #info['number'] = new_file_number if int(info['ID']) in list_of_numbers: print(u"Podany numer ", info['ID'], u'już występuje') raise SystemExit # create all the basic objects (window, fixation-cross, feedback) win = visual.Window(units='norm', color='black', fullscr=True) fixCross = visual.TextStim(win, text='+', height=0.1) negFeedback = visual.TextStim(win, text='X', color='red', height=0.1) win.setMouseVisible(False) # partially apply the helper functions to suite our needs draw = functools.partial(helpers.draw, win) show = functools.partial(helpers.showInstruction, win) wrapdim = functools.partial(helpers.wrapdim, win, height=0.08)
import filehandler as filehandler import helpers as helpers import math # for each node in locations, add a third element to the pair for estimate score Open = [] Closed = [] filehandler.init() temp = helpers.getInput() start = temp[0] end = temp[1] curr = start heuristic = {} path = [] visited = [] for x in temp[2]: del filehandler.Locations[x] # remove that city from Locations dict del filehandler.Connections[x] # remove that city from Connections dict for y in filehandler.Connections: # to remove any connections in other keys for z in filehandler.Connections[y]: if z in temp[2]: filehandler.Connections[y].remove(z) if end not in filehandler.Locations: print( "Destination does not exist in possible locations, you may have removed the destination from search list (intentionally, no doubt)."