Monday 6 January 2020

Python : Dummy service on 9999 port in Linux

#!/usr/bin/python
# Demo server to open port 9999
# Modified from Python tutorial docs
import socket
import sys
HOST = 'localhost'   # IP addresses or Hostname
PORT = 9999 # Open non-privileged port 9999
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print 'Socket created Successfully'
#Bind socket to local host and port
try:
    s.bind((HOST, PORT))
except socket.error as msg:
    print 'Bind failed. Error Code : ' + str(msg[0]) + ' Message ' + msg[1]
    sys.exit()
print 'Socket bind complete'
#Started listening on socket
s.listen(10)
print 'Socket now listening'
while 1:
    #waiting to accept a connection - blocking call
    conn, addr = s.accept()
    print 'Connected with ' + addr[0] + ':' + str(addr[1])
s.close()

save the above file as port_server.py

run the port_server.py in one terminal & try telnet the hostname with 9999

1 comment:

Oracle : Database Startup Time

 Oracle Instance Startup Time SET LINES 2000 SET PAGES 9999 COLUMN INSTANCE_NAME FOR A20 SELECT     instance_name,     to_char(startup_time,...