-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathip-host.ps1
More file actions
45 lines (34 loc) · 1.29 KB
/
ip-host.ps1
File metadata and controls
45 lines (34 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# The following line read a plain list of IPs from files. For this demo, I have
# this line commented out and added a line to just define an array of IPs here
$listofIPs = Get-Content IPList.txt
#$listofIPs = "8.8.8.8","8.8.4.4","10.0.0.2","192.168.2.1"
#Lets create a blank array for the resolved names
$ResultList = @()
# Lets resolve each of these addresses
foreach ($ip in $listofIPs)
{
$result = $null
$currentEAP = $ErrorActionPreference
$ErrorActionPreference = "silentlycontinue"
#Use the DNS Static .Net class for the reverse lookup
# details on this method found here: http://msdn.microsoft.com/en-us/library/ms143997.aspx
$result = [System.Net.Dns]::gethostentry($ip)
$ErrorActionPreference = $currentEAP
If ($Result)
{
$hostname = [string]$Result.HostName
$Resultlist += "$IP,$HOSTNAME"
$temp = "$IP,$HOSTNAME"
$temp
}
Else
{
$Resultlist += "$IP,No Hostname found"
$temp = "$IP,No Hostname found"
$temp
}
}
# If we wanted to output the results to a text file we could do this, for this
# demo I have this line commented and another line here to echo the results to the screen
$resultlist | Out-File output.csv
$ResultList