Created
September 4, 2016 02:38
-
-
Save ChatchaiJ/24aef2dcd3ab1ccf0b7a7c3188af7393 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/python | |
import os | |
import re | |
import subprocess | |
tty = subprocess.check_output("tty") | |
m = re.match(r"/dev/(.+)", tty) | |
line = ".+ " + m.group(1) + " .+" | |
who = subprocess.check_output("who") | |
ip = "" | |
for l in who.split('\n'): | |
if re.match(line, l): | |
m = re.match(r".+\((.+)\).*", l) | |
if m: | |
ip = m.group(1) | |
print "ip = " + ip |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment