アプリ版:「スタンプのみでお礼する」機能のリリースについて

早速ですが、
ネットワーク上のPCのIPとホスト名を取得したいのですが、APIかコマンドから取得できるでしょうか?
(できればAPI)

1.IPからホスト名取得
2.ホスト名からIPアドレスの取得

[環境] windows2000
VB6.0

すみません。教えてください。

A 回答 (2件)

'***共通***


Private Const WS_VERSION_REQD = &H101
Private Const WSADescription_Len = 256
Private Const WSASYS_Status_Len = 128

Private Type WSADATA
wVersion As Integer
wHighVersion As Integer
szDescription(0 To WSADescription_Len) As Byte
szSystemStatus(0 To WSASYS_Status_Len) As Byte
iMaxSockets As Integer
iMaxUdpDg As Integer
lpszVendorInfo As Long
End Type

Private Type HOSTENT
hName As Long
hAliases As Long
hAddrType As Integer
hLength As Integer
hAddrList As Long
End Type

Private Declare Function WSAStartup Lib "WSOCK32.DLL" (ByVal wVersionRequired&, lpWSADATA As WSADATA) As Long

Private Declare Function WSACleanup Lib "WSOCK32.DLL" () As Long

Private Declare Sub RtlMoveMemory Lib "kernel32" (hpvDest As Any, ByVal hpvSource&, ByVal cbCopy&)

'***ホスト名→IP***
Private Declare Function gethostbyname Lib "WSOCK32.DLL" (ByVal HostName$) As Long
'***IP→ホスト名***
Private Declare Function gethostbyaddr Lib "wsock32.dll" (addr As Long, ByVal lngLen As Long, ByVal lngType As Long) As Long

'ホスト名→IPの例
Dim WSAD As WSADATA
Dim lRet As Integer
Dim hostent_addr As Long
Dim host As HOSTENT
Dim hostip_addr As Long
Dim temp_ip_address() As Byte
Dim i As Integer
Dim ip_address As String

'Winsockの使用を開始
lRet = WSAStartup(WS_VERSION_REQD, WSAD)

hostent_addr = gethostbyname("ホスト名")

If hostent_addr = 0 Then
'失敗
End If

RtlMoveMemory host, hostent_addr, LenB(host)
RtlMoveMemory hostip_addr, host.hAddrList, 4

ReDim temp_ip_address(1 To host.hLength)
RtlMoveMemory temp_ip_address(1), hostip_addr, host.hLength

For i = 1 To host.hLength
ip_address = ip_address & temp_ip_address(i) & "."
Next
ip_address = Mid$(ip_address, 1, Len(ip_address) - 1)
'ホスト名ゲット
Text.Text = ip_address

'Winsockの使用を終了
lRet = WSACleanup()

ホスト名→IPは以下のURLを参照
http://vbvbvb.com/jp/gtips/0851/ggethostbyaddr.h …
    • good
    • 0
この回答へのお礼

ありがとうございます。
大変助かりました。

お礼日時:2005/02/18 18:28

#1です。


URLのところの記述は、IP→ホスト名の誤りです。
    • good
    • 0

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!