Skip to content

Instantly share code, notes, and snippets.

@eli2and40
Created August 3, 2020 14:33
Show Gist options
  • Save eli2and40/9d76d9326fb4e3102b0b9422c3369434 to your computer and use it in GitHub Desktop.
Save eli2and40/9d76d9326fb4e3102b0b9422c3369434 to your computer and use it in GitHub Desktop.
"""
Some things are shorter left unsaid
"""
import subprocess, pyperclip
def getIP(copy=False):
"""
Returns the IP address of the device on which the function is called
Dependencies: subprocess.check_result, pyperclip.copy
Arguments: copy=False
Output: ipAddress [str]
"""
call = str(subprocess.check_output('ipconfig')).split('\\n')
line = [l for l in call if 'ipv4' in l.lower()][0]
address = line.strip().strip('. ').strip('\\r').split(': ')[1]
if copy: pyperclip.copy(address)
return address
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment