6

I need to send a username , password and message to a tcp server to get an output that I need for a code challenge that i'm working on. I have been given this set of instructions:

Connect to alien server ('localhost', 10000),
Then send USER followed by aliensignal,
Then send PASS followed by unlockserver,
Next SEND followed by moonbase.
Then send END and if all followed key will provided.

I have written a python code that does exactly what it says:

import socket

clientsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
clientsocket.connect(('localhost', 10000))
clientsocket.send('USER: aliensignal')

clientsocket.send('PASS: unlockserver')
clientsocket.send('SEND: moonbase')
clientsocket.send('END')
data = clientsocket.recv(4096)
print(data)

But i get an output that says:

############# DARKSTORE KEY SERVER SPEC ############################

Set username then password. Once set send name then end connection

and you access key will be sent.


USER: Tell server you will be sending username

PASS: Tell server you will be sending password

SEND: Tell server you will be sending data. (Must be authenticated)

END: Tell server to end transaction. 

######################################################

It gives me this output whether or not I send the username and password. Does anyone know why this is happening?

4
  • Most likely you're supposed to send lines to the server. Otherwise, how does it know the USER isn't "aliensignalPASS:"? Commented Feb 15, 2018 at 21:32
  • @DavidSchwartz How would I send lines? Commented Feb 15, 2018 at 21:33
  • Typically by putting a carriage return and a newline on the end. Commented Feb 15, 2018 at 21:36
  • @DavidSchwartz sorry im new to python. I dont know what a carriage return is. Could you possible post an edited version of the code so i can see? Commented Feb 15, 2018 at 21:39

1 Answer 1

6

Firstly, you don’t need the colons after USER, PASS, SEND and END.

Also, the challenge tells you you need to receive data after every send.

Finally, you need to send the keywords and the data separately

So:

import socket

clientsocket = ...
clientsocket.connect(...)

clientsocket.send(‘USER’)
print(clientsocket.recv(1024))
clientsocket.send(‘aliensignal’)
print(clientsocket.recv(1024))
#etc...
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.