5
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Excel VBAでnslookup

Posted at

使い慣れないので記録を取っておく意味でエントリーしておく.
自前の関数は「標準モジュール」に配置する... と.

 nslookup.bas
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
5
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?