Created
March 12, 2012 14:04
-
-
Save amitu/2022131 to your computer and use it in GitHub Desktop.
get username of the process that opened a connection, works only for case when both client and server are on same machine
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
import time | |
import commands | |
soc = socket.socket() | |
soc.bind(('0.0.0.0', 9996)) | |
soc.listen(5) | |
while True: | |
client, address = soc.accept() | |
print "Connected with: ", address | |
s = commands.getoutput("lsof -i | grep %s | grep -v Python | grep -v sh" % address[1]).split()[2] | |
client.send("hi " + s + "\n") | |
client.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment