Created
October 10, 2013 10:00
-
-
Save katapad/6915932 to your computer and use it in GitHub Desktop.
localhostのアドレスをパッと出すやつ
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
HOST_NAME = do -> | |
os = require('os') | |
interfaces = do os.networkInterfaces | |
checkLocal = (address)-> | |
return address.family is 'IPv4' and not address.internal | |
# en0を優先 | |
if _.has(interfaces, 'en0') | |
for address in interfaces['en0'] | |
if checkLocal(address) | |
return address.address | |
for key,addresses of interfaces then for address in addresses | |
if checkLocal(address) | |
return address.address | |
return 'localhost' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment