hrstt
5/29/2012 - 5:11 AM

Excel VBAでnslookup ref: http://qiita.com/items/3dfc0bd2901b0a71c40c

Option Explicit

Function nslookup(ip As String) As String

  Dim wsh, exec, cmd, res As String, i As Integer
  Dim buf() As String

  Set wsh = CreateObject("WScript.Shell")
  cmd = "nslookup " & ip

  Set exec = wsh.exec("%ComSpec% /c " & cmd)

  Do While exec.Status = 0
    DoEvents
  Loop

  res = exec.StdOut.ReadAll

  buf = Split(res, vbCrLf)

  For i = 0 To UBound(buf)
    If Left(buf(i), 5) = "Name:" Or Left(buf(i), 3) = "名前:" Then
      host_name = Mid(buf(i), 10)
    End If
  Next i

End Function