具有隐藏输入的 python socket.socket.recv
有没有办法让 socket.socket.recv
使用隐藏输入运行。例如,如果我要求输入密码,我希望隐藏输入,就像我正在运行“sudo”bash 命令一样。
编辑:socket.socket.recv
请求远程端的数据。当您连接到服务器时,它会要求您输入文本,当您输入文本时,它将显示在控制台中。现在,当您使用 sudo 命令时,它会要求输入密码,并且您看不到您键入的文本。我想要这样的东西,适用于 socket.sock.recv
,这样您就看不到您输入的密码。
编辑2:
当我说 socket.socket.recv
时,我实际上指的是 socket._socketobject.recv
之类的东西,它在我的程序中看起来像这样: client.recv(BUF_SIZE)
。
编辑3:
我正在制作一个 telnet 服务器。 client.recv(BUF_SIZE)
就像在客户端计算机上运行 raw_input
一样。那么有什么类似于在客户端计算机上运行 getpass.getpass 的东西吗?
Is there any way to have socket.socket.recv
run with hidden input. For example, if I was asking for a password I would want the input to be hidden, as if I were running the "sudo" bash command.
Edit:socket.socket.recv
asks for data on the remote end. When you are connected to the server it will ask you for text and when you type it in it will be shown in your console. Now when you use the sudo command it asks for the password and you can't see the text you type. I want something like this that would work for socket.sock.recv
, so you wouldn't see the password you type.
Edit 2:
When I said socket.socket.recv
I actually meant something like socket._socketobject.recv
which would look like this in my program: client.recv(BUF_SIZE)
.
Edit 3:
I am making a telnet server. client.recv(BUF_SIZE)
is like running raw_input
on the clients computer. So is there anything that is similar to running getpass.getpass
on the clients computer?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
socket.recv()
从套接字返回数据,您如何处理该数据取决于您。我猜你正在做这样的事情:
在这种情况下,你的问题是远程端,可能有人正在输入输入。
您能澄清一下您的问题吗?
recv()
从不单独显示数据。socket.recv()
returns data from a socket, what you do with that data is up to you.I guess you are doing something like this:
In which case your problem is the remote end where someone is presumably typing input.
Can you clarify your question please?
recv()
never displays data by itself.(针对提问者的澄清)
如果您希望能够在控制台(文本模式)提示符下获取用户的输入而不显示它,您可能需要使用
getpass
。然而,这与套接字和网络完全无关。上面的变量
p
包含用户输入的文本(即他们的密码)。如果您使用socket.sendall(p)
将其发送到网络,远程端将收到此数据。此时,由接收脚本决定如何处理数据......(In response to the questioner's clarification)
If you want to be able to obtain input from the user at a console (text-mode) prompt without it being displayed, you probably want to use the
getpass
.However, this has absolutely nothing to do with sockets and networking. The variable
p
above contains the user's entered text (i.e. their password). If you send this down a network withsocket.sendall(p)
the remote end will receive this data. At that point it is up to the receiving script to decide what to do with the data...(响应编辑2)
这是一个简单的示例,说明如何对某些数据是否保密进行编码,并在函数之间传递该数据:
如果您使用套接字,则需要使用 s.sendall( capture() ) 位于一端,
display( s.recv4096) )
位于另一端。(In response to edit 2)
Here is a simple example of how you can encode whether some data is secret or not, and pass that data between functions:
If you are using sockets, you will need to use
s.sendall( capture() )
at one end, anddisplay( s.recv4096) )
at the other.