Hi, all. First post. I need help with what is hopefully a simple script.<\/p>\n
I need to:<\/p>\n
Ping a list of IP addresses in a CSV file.<\/p>\n<\/li>\n
Display the accompanying hostname for each IP.<\/p>\n<\/li>\n
Display what DNS returns on a “ping -a,” basically.<\/p>\n<\/li>\n<\/ol>\n
The CSV looks like this:<\/p>\n
192.168.44.145, Printer1<\/p>\n
192.168.44.148, Printer2<\/p>\n
etc…<\/p>\n
The output should look like:<\/p>\n
192.168.44.145 Printer1 DNS has Printer1<\/p>\n
192.168.44.148 Printer2 DNS has Oldprinter2<\/p>\n
So basically, we have DNS issues and I need a (hopefully) simple script that will compare what we have as the hostname for each, next to what a reverse ping (ping -a) returns from DNS.<\/p>\n
Also, let me add… I don’t even need this to output the results to file. It can just display on the screen and that’s fine.<\/p>\n
All help is appreciated!<\/p>","upvoteCount":5,"answerCount":11,"datePublished":"2023-09-04T13:41:15.000Z","author":{"@type":"Person","name":"spiceuser-l3i98","url":"https://community.spiceworks.com/u/spiceuser-l3i98"},"suggestedAnswer":[{"@type":"Answer","text":"
Hi, all. First post. I need help with what is hopefully a simple script.<\/p>\n
I need to:<\/p>\n
Ping a list of IP addresses in a CSV file.<\/p>\n<\/li>\n
Display the accompanying hostname for each IP.<\/p>\n<\/li>\n
Display what DNS returns on a “ping -a,” basically.<\/p>\n<\/li>\n<\/ol>\n
The CSV looks like this:<\/p>\n
192.168.44.145, Printer1<\/p>\n
192.168.44.148, Printer2<\/p>\n
etc…<\/p>\n
The output should look like:<\/p>\n
192.168.44.145 Printer1 DNS has Printer1<\/p>\n
192.168.44.148 Printer2 DNS has Oldprinter2<\/p>\n
So basically, we have DNS issues and I need a (hopefully) simple script that will compare what we have as the hostname for each, next to what a reverse ping (ping -a) returns from DNS.<\/p>\n
Also, let me add… I don’t even need this to output the results to file. It can just display on the screen and that’s fine.<\/p>\n
All help is appreciated!<\/p>","upvoteCount":5,"datePublished":"2023-09-04T13:41:15.000Z","url":"https://community.spiceworks.com/t/i-need-a-simple-reverse-ping-script/958455/1","author":{"@type":"Person","name":"spiceuser-l3i98","url":"https://community.spiceworks.com/u/spiceuser-l3i98"}},{"@type":"Answer","text":"
There is such a thing as a reverse DNS record; but for some reason they are not terribly popular.<\/p>","upvoteCount":0,"datePublished":"2023-09-04T14:05:55.000Z","url":"https://community.spiceworks.com/t/i-need-a-simple-reverse-ping-script/958455/2","author":{"@type":"Person","name":"andrewleer","url":"https://community.spiceworks.com/u/andrewleer"}},{"@type":"Answer","text":"
I think “reverse ping” would have been a better way for me to put it. We just need to reveal the wrong hostnames in our DNS.<\/p>","upvoteCount":0,"datePublished":"2023-09-04T14:13:44.000Z","url":"https://community.spiceworks.com/t/i-need-a-simple-reverse-ping-script/958455/3","author":{"@type":"Person","name":"spiceuser-l3i98","url":"https://community.spiceworks.com/u/spiceuser-l3i98"}},{"@type":"Answer","text":"
Welcome. What have you tried? Where are you stuck? We’re happy to help but not a script writing service. Post what you have tried and we’ll try to help from there.<\/p>","upvoteCount":1,"datePublished":"2023-09-04T15:35:39.000Z","url":"https://community.spiceworks.com/t/i-need-a-simple-reverse-ping-script/958455/4","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},{"@type":"Answer","text":"
Honestly, I would be just as happy using a plain old batch file. I have a couple I’m working with at the moment. The person who will be running this might also need to run it where PowerShell isn’t available.<\/p>","upvoteCount":0,"datePublished":"2023-09-04T15:46:17.000Z","url":"https://community.spiceworks.com/t/i-need-a-simple-reverse-ping-script/958455/5","author":{"@type":"Person","name":"spiceuser-l3i98","url":"https://community.spiceworks.com/u/spiceuser-l3i98"}},{"@type":"Answer","text":"
As for Powershell, I’m trying this:<\/p>\n
Get-Content \"c:\\temp\\printerping\\printerlist.csv\" |\n ForEach-Object{\n $result = [ordered]@{\n Spreadsheet = $_.Trim()\n DNS = \"$result.DNSName\"\n }\n Try{\n $entry = [System.Net.Dns]::GetHostEntry($_.Trim())\n $result.HostName = $entry.HostName\n \n $entry.AddressList |\n Where-Object {$_.AddressFamily -eq 'InterNetwork'} |\n ForEach-Object{\n $result.DNSIPv4 = $_.IPAddressToString\n [array]$x = Test-Connection -Delay 15 -ComputerName $result.HostName -Count 1 -ErrorAction SilentlyContinue\n if ($x){\n $result.Up = \"Yes\"\n Resolve-DnsName -Name\n }\n else{\n $result.Up = \"No\"\n $result.Up = \"Unknown\"\n \n }\n }\n }\n Catch{\n \n }\n [PSCustomObject]$result\n }\n<\/code><\/pre>\nUnder the “DNS” header, I want it to return the hostname of each IP address, basically the result of a “ping -a” command. Instead, it gives me:<\/p>\n
System.Collections.Specialized.OrderedDictionary.DNSName<\/p>","upvoteCount":0,"datePublished":"2023-09-04T17:07:19.000Z","url":"https://community.spiceworks.com/t/i-need-a-simple-reverse-ping-script/958455/6","author":{"@type":"Person","name":"spiceuser-l3i98","url":"https://community.spiceworks.com/u/spiceuser-l3i98"}},{"@type":"Answer","text":"
While it’s good to learn new things - such as script this, wouldn’t it be simpler to either look in DNS or export your forward and reverse zones so you can see.<\/p>\n
Option 2, tell us about your DNS issues and hopefully we can help without the need to compare DNS records.<\/p>\n
FYI, many people have DNS issues because they configure their DNS to use internal (DCs) and external (Google usually) as their DNS servers, you shouldn’t do this, Google should only ever be used on the DNS server as a forwarder and not elsewhere on the internal network.<\/p>","upvoteCount":0,"datePublished":"2023-09-04T18:06:00.000Z","url":"https://community.spiceworks.com/t/i-need-a-simple-reverse-ping-script/958455/7","author":{"@type":"Person","name":"Rod-IT","url":"https://community.spiceworks.com/u/Rod-IT"}},{"@type":"Answer","text":"
We’re currently working on the DNS issues, but it’s not something I can touch at the moment. We have about 500 printers still ahead that need work and we have to deal with the DNS issues as they arise. Long story. That’s why I want a script that does as described above. Or at batch file. Or a VBS script.<\/p>\n
I guess I made the mistake of thinking this would be simple. It probably is, but I just can’t seem to get it coded right.<\/p>\n
If I could get even just a simple batch file to accomplish what I need, that would be enough. I’ve played with several batch files and scripts today and can’t seem to get it right.<\/p>","upvoteCount":0,"datePublished":"2023-09-04T18:19:08.000Z","url":"https://community.spiceworks.com/t/i-need-a-simple-reverse-ping-script/958455/8","author":{"@type":"Person","name":"spiceuser-l3i98","url":"https://community.spiceworks.com/u/spiceuser-l3i98"}},{"@type":"Answer","text":"
arp -a |grep?<\/p>","upvoteCount":0,"datePublished":"2023-09-05T08:45:04.000Z","url":"https://community.spiceworks.com/t/i-need-a-simple-reverse-ping-script/958455/9","author":{"@type":"Person","name":"robertgolobek","url":"https://community.spiceworks.com/u/robertgolobek"}},{"@type":"Answer","text":"
You could do something like:<\/p>\n
get-content .\\ipaddresses.txt | Resolve-DnsName | Select Name,NameHost\n<\/code><\/pre>","upvoteCount":2,"datePublished":"2023-09-05T09:13:07.000Z","url":"https://community.spiceworks.com/t/i-need-a-simple-reverse-ping-script/958455/10","author":{"@type":"Person","name":"martin9700","url":"https://community.spiceworks.com/u/martin9700"}},{"@type":"Answer","text":"So what is the proper tag/element to give me the returned hostname for a reverse ping (ping -a)?<\/p>\n
The one I use above is giving me:<\/p>\n
System.Collections.Specialized.OrderedDictionary.DNSName<\/p>","upvoteCount":0,"datePublished":"2023-09-05T16:31:37.000Z","url":"https://community.spiceworks.com/t/i-need-a-simple-reverse-ping-script/958455/11","author":{"@type":"Person","name":"spiceuser-l3i98","url":"https://community.spiceworks.com/u/spiceuser-l3i98"}}]}}