Skip to content

Instantly share code, notes, and snippets.

@hymkor
Created September 18, 2014 02:01
Show Gist options
  • Save hymkor/fadd5ce20b4c09008029 to your computer and use it in GitHub Desktop.
Save hymkor/fadd5ce20b4c09008029 to your computer and use it in GitHub Desktop.
ゲストOSからホストOSのIPアドレスを確実に得るにはどうすればいいんだ。みんなの知恵をわけてくれ ref: http://qiita.com/zetamatta/items/73b294ba923f479b9907
::rem:: --[[ vim:set ft=lua:
@lua "%~f0" %1 %2 %3 %4 %5 %6 %7 %8 %9 & exit /b
]]--
function getGateway()
local ipconfig = io.popen("ipconfig","r")
for line in ipconfig:lines() do
local m = line:match("デフォルト.*%s([0-9]+%.[0-9]+%.[0-9]+%.[0-9]+)")
if m then
ipconfig:close()
return m
end
end
ipconfig:close()
end
print(getGateway())
✏ hostip
10.0.2.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment