Created
August 3, 2020 14:33
-
-
Save eli2and40/9d76d9326fb4e3102b0b9422c3369434 to your computer and use it in GitHub Desktop.
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
""" | |
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