Skip to content

Instantly share code, notes, and snippets.

@ChatchaiJ
Created September 4, 2016 02:38
Show Gist options
  • Save ChatchaiJ/24aef2dcd3ab1ccf0b7a7c3188af7393 to your computer and use it in GitHub Desktop.
Save ChatchaiJ/24aef2dcd3ab1ccf0b7a7c3188af7393 to your computer and use it in GitHub Desktop.
#!/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