1

I want to make a python script run on a socket of server in LAN. I wrote a number guessing script and i want to make it run on socket for other clients to play with it by connecting to port (say 1234). I know to achieve this by socket programming from python. But this question is to ask as to why this fails?

ncat 192.168.0.108 -lvp 1234 -e /usr/bin/python3.5 number_game.py

the script:

#!/usr/bin/python3.5
import random
num=random.randint(1,20)
flag=0
print("Welcome to the game...")
for i in range(1,7):
    print("Take a guess")
    guess=int(input())
    if guess > num:
        print("Way too high")
    else:
        if guess < num:
            print("Way too low")
        else:
            flag=1
            break;
if flag == 1:
    print("You made it in "+str(i)+" attempts")
else:
    print("better luck next time")

the error:

Ncat: Version 7.31 ( https://nmap.org/ncat ) Ncat: Got more than one port specification: 1234 number_game.py. QUITTING.

1
  • The manpage says: ncat [OPTIONS...] [hostname] [port]. You should surround your command with quotes: -e '/usr/bin/python3.5 number_game.py', as otherwise number_game.py is inerpreted as port number (see the error message). – ridgy Jan 2 '17 at 12:05
4

Solution

You are trying to listen on the port 1234, and to connect to machine with the IP 192.168.1.108 in the same time.

You can't do that, you either listen for the connection using this :

ncat -lvp 1234 -e "/usr/bin/python3.5 number_game.py"`

or you initiate the connection to the desired machine using this :

ncat -v -e "/usr/bin/python3.5 number_game.py" 192.168.0.108 1234

Note

When you use ncat (or nc) to initiate the connection, you have to keep the IP (or hostname) and the port the last parameters.

Look to the synopsis of ncat in the manual : ncat [OPTIONS...] [hostname] [port]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.