doing a whois in excel

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
The code below will create a user defined function. To use it, put the following in cells B1, C1 and D1:

B1 ---> =whois(A1,"NetRange")
C1 ---> =whois(A1,"Name")
D1 ---> =whois(A1,"Organization")




Function WhoIs(ByVal tRange As Range, ByVal tItem As String) As String

Dim xmlhttp As Object
Dim r, c As Integer
Dim t As String

r = tRange.Row
c = tRange.Column

ip = Cells(r, c).Text

Set xmlhttp = CreateObject("msxml2.xmlhttp.3.0")
xmlhttp.Open "get", "http://whois.arin.net/rest/nets;q=" & ip & "?showDetails=true&showARIN=false&ext=netref2", False
xmlhttp.send
t = xmlhttp.ResponseText

Select Case UCase(tItem)
Case "NETRANGE"
t = Mid(t, InStr(t, "<endAddress>") + 12)
WhoIs = Left(t, InStr(t, "<") - 1) & " - "
t = Mid(t, InStr(t, "<startAddress>") + 14)
WhoIs = WhoIs & Left(t, InStr(t, "<") - 1)
Case "NAME"
t = Mid(t, InStr(t, "<name>") + 6)
WhoIs = Left(t, InStr(t, "<") - 1)
Case "ORGANIZATION"
t = Mid(t, InStr(t, "<orgRef name=") + 14)
WhoIs = Left(t, InStr(t, Chr(34)) - 1) & " ("
t = Mid(t, InStr(t, "handle=") + 8)
WhoIs = WhoIs & Left(t, InStr(t, Chr(34)) - 1) & ")"
End Select

End Function
 
Last edited:
Upvote 0
Sorry, the code didn't post correctly. The software is interpreting some of my code as XML or something. For these lines:

t = Mid(t, InStr(t, "< endAddress>") + 12)
t = Mid(t, InStr(t, "< startAddress>") + 14)
t = Mid(t, InStr(t, "< name>") + 6)
t = Mid(t, InStr(t, "< orgRef name=") + 14)

...remove all spaces from inside the quotes (ie. the space after the < character). I had to add the space to get the code to post.



Function WhoIs(ByVal tRange As Range, ByVal tItem As String) As String

Dim xmlhttp As Object
Dim r, c As Integer
Dim t As String

r = tRange.Row
c = tRange.Column

ip = Cells(r, c).Text

Set xmlhttp = CreateObject("msxml2.xmlhttp.3.0")
xmlhttp.Open "get", "http://whois.arin.net/rest/nets;q=" & ip & "?showDetails=true&showARIN=false&ext=netref2", False
xmlhttp.send
t = xmlhttp.ResponseText

Select Case UCase(tItem)
Case "NETRANGE"
t = Mid(t, InStr(t, "< endAddress>") + 12)
WhoIs = Left(t, InStr(t, "<") - 1) & " - "
t = Mid(t, InStr(t, "< startAddress>") + 14)
WhoIs = WhoIs & Left(t, InStr(t, "<") - 1)
Case "NAME"
t = Mid(t, InStr(t, "< name>") + 6)
WhoIs = Left(t, InStr(t, "<") - 1)
Case "ORGANIZATION"
t = Mid(t, InStr(t, "< orgRef name=") + 14)
WhoIs = Left(t, InStr(t, Chr(34)) - 1) & " ("
t = Mid(t, InStr(t, "handle=") + 8)
WhoIs = WhoIs & Left(t, InStr(t, Chr(34)) - 1) & ")"
End Select

End Function
 
Upvote 0
You can work with the range directly without converting it to rows and columns:

ip=tRange.Text
 
Upvote 0
The previous code had the range values backwards. This will fix that, and I reformatted it so it will show up correctly in this forum:

Code:
Function WhoIs(ByVal tRange As Range, ByVal tItem As String) As String

    Dim xmlhttp As Object
    Dim r, c As Integer
    Dim t As String
    
    r = tRange.Row
    c = tRange.Column
    
    ip = Cells(r, c).Text
    
    Set xmlhttp = CreateObject("msxml2.xmlhttp.3.0")
    xmlhttp.Open "get", "http://whois.arin.net/rest/nets;q=" & ip & "?showDetails=true&showARIN=false&ext=netref2", False
    xmlhttp.send
    t = xmlhttp.ResponseText
    
    Select Case UCase(tItem)
        Case "NETRANGE"
            t = Mid(t, InStr(t, "<" & "endAddress>") + 12)
            WhoIs = Left(t, InStr(t, "<") - 1)
            t = Mid(t, InStr(t, "<" & "startAddress>") + 14)
            WhoIs = Left(t, InStr(t, "<") - 1) & " - " & WhoIs
        Case "NAME"
            t = Mid(t, InStr(t, "<" & "name>") + 6)
            WhoIs = Left(t, InStr(t, "<") - 1)
        Case "ORGANIZATION"
            t = Mid(t, InStr(t, "<" & "orgRef name=") + 14)
            WhoIs = Left(t, InStr(t, Chr(34)) - 1) & " ("
            t = Mid(t, InStr(t, "handle=") + 8)
            WhoIs = WhoIs & Left(t, InStr(t, Chr(34)) - 1) & ")"
    End Select

End Function
 
Upvote 0
Thanks mjbeam!

Can I submit a change request here ... How do I add a <Case "ALL"> where B1, C1 and D1 are all populated with NETRANGE, NAME, ORGANIZATION in one go? This way, I wouldn't have to make 3 xmlhttp.open, which is slow. Appreciate all your help!
 
Upvote 0
You will have to enter this as an array formula on the spreadsheet. For example, enter 15.185.186.215 in cell A1. Then select cells B1-D1, and in the formula editor enter the formula:

=WhoIs2(A1)

Then press Shift-Ctrl-Enter.

Code:
Function WhoIs2(ByVal tRange As Range) As Variant

    Dim xmlhttp As Object
    Dim s, t As String
    Dim WhoIsArray(3) As Variant
    
    ip = tRange.Text 'Props to Scott Huish
    
    Set xmlhttp = CreateObject("msxml2.xmlhttp.3.0")
    xmlhttp.Open "get", "http://whois.arin.net/rest/nets;q=" & ip & "?showDetails=true&showARIN=false&ext=netref2", False
    xmlhttp.send
    s = xmlhttp.ResponseText
    
    t = Mid(s, InStr(s, "<" & "endAddress>") + 12)
    WhoIsArray(2) = Left(t, InStr(t, "<") - 1)
    t = Mid(t, InStr(t, "<" & "startAddress>") + 14)
    WhoIsArray(2) = Left(t, InStr(t, "<") - 1) & " - " & WhoIsArray(2)

    t = Mid(s, InStr(s, "<" & "name>") + 6)
    WhoIsArray(0) = Left(t, InStr(t, "<") - 1)

    t = Mid(s, InStr(s, "<" & "orgRef name=") + 14)
    WhoIsArray(1) = Left(t, InStr(t, Chr(34)) - 1) & " ("
    t = Mid(t, InStr(t, "handle=") + 8)
    WhoIsArray(1) = WhoIsArray(1) & Left(t, InStr(t, Chr(34)) - 1) & ")"
    
    WhoIs2 = WhoIsArray

End Function
 
Last edited:
Upvote 0
I noticed that I didn't output the NetRange, Name, and Organization in the order you asked for. To correct this you can change the WhoIsArray index values to what you want. In the example above, WhoIsArray(0) will go into cells B1,WhoIsArray (1) to cell C1, and WhoIsArray(2) will go to cell D1. To fix the code change the indexes as needed. If this isn't clear let me know and I'll fix it for you.
 
Upvote 0
mjbeam no worries, I was trying to avoid using an array formula so I'll just let it run ... Thanks!.
 
Upvote 0

Forum statistics

Threads
1,215,086
Messages
6,123,033
Members
449,092
Latest member
ikke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top