Advertisement
Jackspade9624

ophish.py

Jun 6th, 2025
9
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. import socket
  2. import argparse
  3. import sys
  4. import datetime
  5.  
  6. def listen_and_save(ip, port, filename):
  7. """ Listens for incoming traffic on the specified IP and port, and saves the data to a file.
  8. """
  9. try:
  10. # Create a socket object
  11. s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  12.  
  13. # Bind the socket to the specified IP and port
  14. s.bind((ip, port))
  15.  
  16. # Start listening for incoming connections
  17. s.listen(1) # Listen for a maximum of 1 connection at a time
  18.  
  19. print(f"[*] Listening on {ip}:{port}")
  20.  
  21. # Accept a connection from a client
  22. conn, addr = s.accept()
  23. print(f"[*] Connection from: {addr[0]}:{addr[1]}")
  24.  
  25. # Open the file for writing
  26. with open(filename, 'a') as f:
  27. while True:
  28. # Receive data from the connection
  29. data = conn.recv(1024)
  30.  
  31. # If no data is received, the connection is closed
  32. if not data:
  33. break
  34.  
  35. # Write the received data to the file
  36. timestamp = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
  37. f.write(f"[{timestamp}] Received from {addr[0]}:{addr[1]}: {data.decode()}\n")
  38. print(f"Received data: {data.decode()}")
  39.  
  40. print("[*] Connection closed")
  41. conn.close()
  42.  
  43. except socket.error as e:
  44. print(f"[!] Socket error: {e}")
  45. except Exception as e:
  46. print(f"[!] An error occurred: {e}")
  47. finally:
  48. s.close() # Close the socket
  49.  
  50. def main():
  51. parser = argparse.ArgumentParser(description="IP Listening Tool")
  52. parser.add_argument("-i", "--ip", help="IP address to listen on", required=True)
  53. parser.add_argument("-p", "--port", type=int, help="Port to listen on", required=True)
  54. parser.add_argument("-o", "--output", help="Output file to save data", required=True)
  55.  
  56. args = parser.parse_args()
  57.  
  58. listen_and_save(args.ip, args.port, args.output)
  59.  
  60. if __name__ == "__main__":
  61. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement