Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IP Lookup

Status
Not open for further replies.

gurner

Technical User
Joined
Feb 13, 2002
Messages
522
Location
US
Might come in handy?

might figure out how to automate it from reading IIS logs, when i get the time.

very simple but effective (unless the IP is spoofed)

------------------

dim response
response = inputbox("Please type an IP address to lookup in the box and click OK.", "IP Lookup - Gurner")
if response <> "" then
msgbox "You typed " & response & ".", 64, "Is this correct?"
end if

set ie = createobject("internetexplorer.application")
ie.top = 5
ie.left = 80
ie.width = 800
ie.height = 600
ie.navigate " & response & ""
ie.visible = true

--------------------------




Gurner

 
Or just script [tt]nslookup.exe[/tt], much lighter-weight solution then loading up an IE instance and doing a web query.
 
yeah, could do, just thought you got more detailed information from dnsstuff such as location down to either registered location of IP owner such as an Org or ISP

Gurner

 
Not sure if anyone would get any use out of this SIMILAR script, but we had issues with abusive emails comeing into our network that we had to deal with, they were coming from IP addresses only, so I harvested the IP addresses, then then processed them to find out where they came from, then we sent abuse reports to the ISP's abuse mailboxes. Those abuses stopped shortly thereafter. Here's the code if anyone's interested.
Code:
Dim WshNetwork, FSO, WshShell

Set WshNetwork = WScript.CreateObject("WScript.Network")
Set WshShell = WScript.CreateObject("WScript.Shell")
Set FSO = CreateObject("Scripting.FileSystemObject")


NamePosition = 10
NameSpaces = 50
AddressPosition = 11
AdressSpaces = 15
BadPosition = 1
BadSpaces = 15


'''''''''''''''''''''''''''''''''''''''''''''''''''
' +---------------------------------------------+
' | Error Checking.  Checks for File to process	|
' | If File does not exist, Program quits.		|
' +---------------------------------------------+
'''''''''''''''''''''''''''''''''''''''''''''''''''
If not (fso.FileExists("c:\AbuseIPAddresses.txt")) Then
		msgbox(	"               ----------------------------------------" & vbCrLf & _
				"                                E R R O R " & vbCrLf & _
				"               ----------------------------------------" & vbCrLf & vbCrLf & _
				"The file ""C:\AbuseIPAddresses.txt"" Does NOT" & vbCrLf & _
				"                 Exist.  Script will now quit.")
		WScript.quit
end if


'''''''''''''''''''''''''''''''''''''''''''''''''''
' +---------------------------------------------+
' | Process										|
' +---------------------------------------------+
'''''''''''''''''''''''''''''''''''''''''''''''''''
set namelookup = fso.openTextFile("c:\NameOfIP.txt",2,true)
namelookup.close

set NonResolveIP = fso.openTextFile("C:\BadIP.txt",2,true)
NonResolveIP.close

set abuseip = fso.openTextFile("c:\AbuseIPAddresses.txt",1,true)

do while not abuseip.atEndOfStream
	GetName = abuseip.readLine
	rc=wshshell.run("cmd /c nslookup """ & GetName & """ >> c:\NameOfIP.txt ",1,True)
loop
abuseip.close

set namelookup = fso.openTextFile("c:\NameOfIP.txt",1,true)
set NameIP = fso.openTextFile("C:\AbuseIP.txt",2,true)
set ProcessedIP = fso.openTextFile("C:\ProcessedIP.txt",2,true)

NameIP.writeline("IP Address       Resolved Address")
NameIP.writeline("_______________  __________________________________________________")

do while not namelookup.atEndOfStream
	Spaces = ""
	ProcName = namelookup.readLine
	Name = InStr(ProcName,"Name:")
	If Name = 1 then
			DNSName = mid(ProcName, NamePosition, NameSpaces)
			ProcIP = namelookup.readline
			IPAddy = mid(ProcIP, AddressPosition, AdressSpaces)
			For x = 1 to (17-len(IPAddy))
				Spaces = Spaces + " "
			next
			ProcessedIP.writeline IPAddy
			NameIP.writeline IPAddy & Spaces & DNSName
	End If
loop
namelookup.close
nameip.close
processedip.close

set abuseip = fso.openTextFile("c:\AbuseIPAddresses.txt",1,true)
set ProcessedIP = fso.openTextFile("C:\ProcessedIP.txt",1,true)
set NonResolveIP = fso.openTextFile("C:\BadIP.txt",2,true)

NonResolveIP.writeline("IP Address       Resolved Address")
NonResolveIP.writeline("_______________  __________________________________________________")

do while not ProcessedIP.atEndOfStream
	FoundMatch = 0
	Spaces = "  "
	processed = ProcessedIP.readLine
	do while not abuseip.atEndOfStream
		abuseiveip = abuseip.readLine
		BadAddy = mid(abuseiveip, BadPosition, BadSpaces)
		if processed = BadAddy then
				FoundMatch = 1
				exit do
			else
				if len(BadAddy) = 15 then
						Spaces = "  "
					else
						For x = 1 to (15-len(BadAddy))
							Spaces = Spaces + " "
						next
				end if

				If FoundMatch = 0 then
						NonResolveIP.writeline(BadAddy & Spaces & "Unable to resolve IP Address.")
				end if
		end if
	loop
loop
abuseip.close
processedip.close
nonresolveip.close

fso.deletefile("c:\NameOfIP.txt")
fso.deletefile("C:\ProcessedIP.txt")

wshshell.run("notepad C:\AbuseIP.txt")
wshshell.run("notepad C:\BadIP.txt")


'''''''''''''''''''''''''''''''''''''''''''''''''''
' +---------------------------------------------+
' | END OF PROGRAM								|
' +---------------------------------------------+
'''''''''''''''''''''''''''''''''''''''''''''''''''
msgbox("Done")
WScript.quit
I appologize for the excess tab's, but you should be able to get it.

-SWarrior
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top