I just failed a job interview Sup Forums. They asked me to write a program (they recommended in Python, but would accept any language) that: the client: accepts a host and port number from the command line Requests the Quote of the Day from the specified host (different network) over UDP Prints the resulting quote only accepts responses from specified server and times out after 10 seconds
The server should: accept a port number from the command line Receive requests from any address Reply to requests with the Quote of the Day
I've scoured the internet, and I haven't found much except it's outdated, and port 17 is important.
Does anyone know how to do this?
Julian Russell
They also asked me to do it over TCP as well--couldn't figure that one out either
Xavier Nguyen
Does python not have a sockets library of some kind?
Jack Murphy
It does Import sockets I think Import sys is also needed
Samuel Moore
Don't ask here, we don't want more Indians writing shitty code. If you can't do it maybe you're not up for the job.
Juan Perry
Everyone who knows how to do it at one point didn't at an earlier point. Plus you obviously have no idea what's being discussed. There's no market for Indians that can do an outdated qotd.
James Collins
this is a joke right?
literally read up on your language's socket lib.
worst case you have to use some line buffer reader on top of your socket
Christian Edwards
Give it back Jamal
Colton Wilson
Should have wrote it in Rust, OP.
Brayden Martin
This is covered in the book Blackhat Python. Maybe you should read books
Cameron Wright
ITT: >I've applied for a job clearly out of my league and failed
So what?
Lucas King
I think I have that book let me check
Hudson Powell
So I want to learn so it's not out of my league. Such defeatist attitudes here.
Xavier Bell
>Blackhat Python >needing to be a blackhat to open a fucking socket What a joke. You python guys suck.
Justin Scott
This board is full of NEETs who actually have no idea what they're doing bro. Sorry it didn't work out for you, I can barely read code so I'm not useful but I was looking forward to someone implementing this here as well so I could learn a thing.
Luke Smith
read up on sockets and network protocols in your language of choice. If you don't even have the drive to work this kind of shit out yourself there is literally no hope for you.
Robert Sanchez
>Everyone who knows how to do it at one point didn't at an earlier point. ... and he took some time to research it and read the documents if they was not an idiot.
Tyler Wilson
why udp? are those guys retarded?
Robert Sanders
How long did they give you? Were you allowed to google stuff?
Aiden Parker
Why sockets instead of HTTP? It's just a fucking quote...
Probably they wanted to see how he implements a reliable channel over UDP.
William Cruz
Thanks dude. Unfortunately you're correct. I have. There's a lot of material, I'll post what I've tried in just a second
They wanted both over udp and tcp. (In different qotds of course)
It was quickly obvious I didn't know. I wasn't allowed to Google it, but I did when I went home, and there's very little as to how to actually do it.
Only leads I have is the python socket library, and port 17.
Jayden Flores
HTTP is TCP moron.
Dominic Parker
>if they was not an idiot what did he mean by this?
Hunter Adams
OK I have 3 files: import socket import sys
def main(): #Get a socket using the IPv4 address sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) dest_ip = input("Enter the server ip:") dest_port = int(input("Enter the server port #:")) dest_add = (dest_ip, dest_port) sock.connect(dest_add)
try: message = 'Message sent.' print('Sending message') sock.sendall(message.encode()) received = 0 needed = len(message.encode()) while received < needed: data = sock.recv(16) received += len(data) print(sys.stderr, 'received "%s"' % data) finally: sock.close() if __name__ == '__main__': main() #end py
import socket import sys
# Create a UDP socket sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
server_address = ('localhost', 10000) message = 'This is the message. It will be repeated.'
try:
# Send data print(sys.stderr, 'sending "%s"' % message) sent = sock.sendto(message.encode(), server_address)
# Receive response print(sys.stderr, 'waiting to receive') data, server = sock.recvfrom(4096) print(sys.stderr, 'received "%s"' % data)
Quote of the day is a method to check connectivity between networks
Aaron Morgan
#server py import socket import sys
# Create a TCP/IP socket sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# Bind the socket to the port #to_ip = input("Enter IP: ") server_address = ('localhost', 10000) print(sys.stderr, 'starting up on %s port %s' % server_address) sock.bind(server_address) sock.listen(1)
while True: print(sys.stderr, '\nwaiting to receive message') connection, client_address = sock.accept()
try: print(sys.stderr, 'Connected to: ', client_address) while True: data = connection.recv(16) print(sys.stderr, 'received %s bytes ' % len(data)) if data: connection.sendall(data) else: break finally: connection.close()
This was all for UDP, I think TCP I'd just need to make a few substitutions somewhere once these files work
Dominic Myers
>This was all for UDP, I think TCP I'd just need to make a few substitutions somewhere once these files work disregard that... I had a brain fart
Sebastian Fisher
what was the position? network engineer?
Caleb Ward
>input You're fired!
Caleb Evans
I never said i was a good python coder kek
this works when I do it locally, but fails when i try to internetwork (yes I changed localhost to the ip)
Tyler Perry
They asked you to pass the parameters from the command line my man.
Connor Morales
shit. would I just do args[1] or argv[1] or something similar?
Asher Gonzalez
Yeah, and checking if you have enough args to do what you want.
Adrian Harris
op is a fag
Owen Sanders
Also, an obvious follow up would be asking you to handle exceptions and maybe even use something like optparse.
Landon Wood
is this a troll thread?
Nathaniel Walker
no one can answer it so how much trolling is it really
Elijah Harris
Bump
Sebastian Peterson
Please read the board sticky before posting.
Python is a language with semantically important whitespace, so posting without code tags to preserve the formatting is a very bad idea.
>this works when I do it locally, but fails when i try to internetwork Sounds like the server is behind a firewall/router with closed ports.
Parker Watson
>firewall router with closed ports Oh my god thank you, that might just be it
Owen Sanchez
what kind of job was this for? What was the description for it?
Jonathan Davis
Also would just the ipv4 address given by entering "ipconfig" into cmd be sufficient? (And the port number of course) I'll try disabling the firewalls when I get back. Honestly it was just tech support at a university. They have to deal with several servers, routers, and networks.
Thomas Adams
Depends on your network setup. That IP may just be the server's address on the local area network, so trying to connect to it will only work if the client is also on the same network. If you're just testing between two computers (server and client) both connected to your router it should be fine without needing to fiddle with firewalls/port forwarding.
Also in what I guess is your server it looks like you're listening on localhost only. Probably simplest to change this to ANY address ("0.0.0.0"), that might also fix your issue.
For big/multi-file source posting I'd suggest you use a pastebin (pastebin.com, paste.installgentoo.com, github gists, etc)
Matthew Stewart
> Honestly it was just tech support at a university.
And this is where your lies unravel. I was suspicious when I read that this was asked in a job interview, mainly because there is a lot to consider in the requested program that could add up to a lot of programming time which no one wants to sit around waiting for you to figure out. Come on, command line? There's too much to go wrong for an interview, it's too much, even for a software engineering position...but tech support?
***Congratulate OP, everyone, on his/her social hacking skills. Fully knowing how poorly this board looks down on people looking for homework help, they tricked you into doing for them!***
Carson Garcia
So they basically asked you to write a command line task and a server-side API. I have no idea how do you make server scripts in Python, but it shouldn't be too hard.
Port 17 is not actually "important". It's just a commonly used port for the purpose. When you're setting up the server, you can use whatever port you want (unless it's already in use).
So you need:
1) Make a UDP request to a specific URL. 2) Return specific data from the response 3) Set up a listener on a specific url:port Optionally: Set up port forwarding, so the client doesn't have to input port manually.
A listener is literally a controller action that's triggered by external requests and is set up to process them.
That's assuming your server works in MVC. Google how to do these things in Python and you're done.
Oliver Peterson
>could add up to a lot of programming time If we talk about Ruby on Rails, I can make you a setup in less than 20 minutes.