Dim wd As WSADATA Dim host As *HOSTENT Dim addr As DWord Dim i$ As String Dim s[555] As Byte
WSAStartup( MAKEWORD(2,0), wd) Print "簡易nslookup"
While 1 Print "ホストまたはIPアドレスを入力してください。" Print "やめるときはexitと打ってください" Input i$ If i$="exit" Then Exit While lstrcpy(s, StrPtr(i$)) If IPorHost(s)=IP Then addr=inet_addr(s) host=gethostbyaddr(VarPtr(addr), SizeOf(DWord), AF_INET) Else host=gethostbyname(s) End If PutHostInfo(host) Print "" Wend WSACleanup() End
'文字列からIP,HOSTの判別 Function IPorHost(s As *Byte) As Long Dim i As Long IPorHost=HOST While s[i] If IsCharAlpha(s[i])=TRUE Then Exit Function i++ Wend IPorHost=IP End Function
'取得したホスト情報の表示 Sub PutHostInfo(host As *HOSTENT) Dim i As Long If host=NULL Then Print "ホスト情報の取得失敗" Exit Sub End If Print "正式名 : "+MakeStr(host->h_name) While host->h_aliases[i] Print "別名 : "+MakeStr(host->h_aliases[i]) i=i+1 Wend i=0 While host->h_addr_list[i] Print "IP : "+MakeStr(inet_ntoa(GetDWord(host->h_addr_list[i]))) i=i+1 Wend End Sub