Find All IPs with a specific hop in the trace

Hi Experts..

I need a PowerShell script to Tracert an entire range (For Example 10.20.30.[0-255])
And search for a specific Address as one of the hops (For example 10.56.44.12)
and if that address appears, that address will be appended to a simple text file.

Any ideas?
LVL 8
David SankovskySenior SysAdminAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Brian MurphyIT ArchitectCommented:
Is ICMP enabled?

If so, you could start with tracert -d (no DNS resolution).

I just want to make sure ICMP is not disabled before I suggest next steps for Powershell.

Apologies.
0
David SankovskySenior SysAdminAuthor Commented:
The computer that will be running the script is open with DMZ to the entire range, and ICMP is certainly enabled on both the sources (10.20.30.0-255) and the Destination 10.56.44.12 (These are example addresses)

There might be addresses in the path that won't answer though.
Also, if it's relevant, we can't assume the required IP Address will always be the same hop.
0
Brian MurphyIT ArchitectCommented:
What are we working with?  

.NET 4.5.2 with MS Management Framework 4.0 aka Powershell 4 is good.

.NET 4.6 with MS Management Framework 5.0 aka Powershell 5 with DSC better

Either works, which one?
0
ON-DEMAND: 10 Easy Ways to Lose a Password

Learn about the methods that hackers use to lift real, working credentials from even the most security-savvy employees in this on-demand webinar. We cover the importance of multi-factor authentication and how these solutions can better protect your business!

Brian MurphyIT ArchitectCommented:
So that I'm clear, all you want to do is pass a variable to a range or array of IP?

So, mytrace 10.56.44.12

And output all the "hops" to get at that IP?

Is it one subnet?  There are no hops, yes?  I'm missing something.  It happens.
0
Brian MurphyIT ArchitectCommented:
I'm thinking...

Test-Connection, BTW.

That is our start point.  Probably.
0
Brian MurphyIT ArchitectCommented:
If you have older versions, we can use WMI - possibly
0
Brian MurphyIT ArchitectCommented:
Well, someone beat me to it.  If this works, we should not make a new wheel.  I'm not convinced yet it will do what you want, however.  Because I'm not sure what that is, yet.

https://gallery.technet.microsoft.com/scriptcenter/Ping-tool-Ping-Check-to-353f75ce

They probably used Sapien Powershell Studio.  That is what I used, they compiled a binary script that pings but also gives TTL.  

Ping Admin tool is powerful tool based on PowerShell scripting.
Using Power Admin tool you can Ping to Single, multiple Server/computers or IP range.
Moreover, Ping Admin tool gives you OS type as well in the output, along with FQDN and IP address.
If, IP range selected then it will show TTL value as well.
0
David SankovskySenior SysAdminAuthor Commented:
$PSVersionTable.PSVersion
Major  Minor  Build  Revision
-----  -----  -----  --------
5      0      10240  16384
[System.Reflection.Assembly]::GetExecutingAssembly().ImageRuntimeVersion
 v4.0.30319
0
Brian MurphyIT ArchitectCommented:
Your going to need WMF 5.0 for the good stuff
http://www.powershellgallery.com/
0
Brian MurphyIT ArchitectCommented:
That works, but there are some awesome new SDK's for WMF 5.0

I could not get that ping tool to run

https://gallery.technet.microsoft.com/scriptcenter/xNetworking-Module-818b3583
0
David SankovskySenior SysAdminAuthor Commented:
I'd rather not install too many additional modules on the server that will be executing the script
0
Brian MurphyIT ArchitectCommented:
Still, what is the output look like in your dimension?  Take out the text file for a moment....

Here is a very basic port scan, 1 liner.  But you said something about finding a specific IP in a subnet or subnets?  What is the deliverable here?

IPAddress          HostName          Ports          
---------          --------          -----          
10.0.0.2          DC01.hacme.local      {53, 139, 389, 445...}
10.0.0.3          SRV01.hacme.local     {21, 80, 139, 445...}
10.0.0.10        SP01.hacme.local      {80, 139, 445}
0
Brian MurphyIT ArchitectCommented:
The # of IP's changes the design.  Look at Test-Connection and the difference between async and sync scans.

Asynchronous IP range scan:
Days              : 0
Hours             : 0
Minutes           : 0
Seconds           : 18
Milliseconds      : 199
Ticks             : 181999900
TotalDays         : 0.000210648032407407
TotalHours        : 0.00505555277777778
TotalMinutes      : 0.303333166666667
TotalSeconds      : 18.19999
TotalMilliseconds : 18199.99

Synchronous IP range scan:
Days              : 0
Hours             : 0
Minutes           : 1
Seconds           : 4
Milliseconds      : 667
Ticks             : 646679415
TotalDays         : 0.000748471545138889
TotalHours        : 0.0179633170833333
TotalMinutes      : 1.077799025
TotalSeconds      : 64.6679415
TotalMilliseconds : 64667.9415
0
David SankovskySenior SysAdminAuthor Commented:
I may have not explained myself properly.
I have a certain range 10.20.30.0\24
I need to use the command tracert -d for each and every address in the range,
Then to scan the output for a certain hop (10.56.44.12 for example) and then to write to a file only those addresses which have that speific address in the trace.

(To make it simpler to understand the point of the exercise, I have two firewalls, both sitting behind Junipers, Some addresses are routed to the old firewall and some to the new. I need to those which are routed to the old one to know which ones I have to migrate. Since the person managing the Juniper Routers is out of the country for the next couple of months, I'll have to do it this way as I have no CLI access to the Juniper router)
0
Brian MurphyIT ArchitectCommented:
Much better.  Thanks.  I did not understand, this helps.
0
Brian MurphyIT ArchitectCommented:
Ah man.  No CLI Access?  So much easier.
0
Brian MurphyIT ArchitectCommented:
So, NMAP
https://nmap.org/

Does all that and more, you just populate your text file with your ranges or CSV and it will export everything out to whatever you want; txt, csv, html.

I run it on Linux and Windows.  I have on my MGMT server in the DMZ.  Along with a bunch of other cool stuff.

I mean, I'm willing to play but what your asking is not something I can pull off in a day.  But I'll help if NMAP is not an option for you.
0
Brian MurphyIT ArchitectCommented:
Actually, David.  I forgot about hdping.

It is still supported.

And free, http://www.hping.org/

https://www.youtube.com/watch?v=RMC84O1Lm2M

But, not sure it will do "exactly" what you want so I'll start looking at Powershell options.  I have a few ideas.
0
Dan CraciunIT ConsultantCommented:
Use this for a start:
$ipClass = "10.20.30."
$ipStart = 1
$ipEnd = 254
$resultsFile = "X:\your\results\file.txt"

for ($i = $ipStart; $i -le $ipEnd; $i++) {
    $ip = $ipClass + [string] $i
    $traceResult = Test-NetConnection $ip -traceroute
    if ($traceResult.TraceRoute -like "*10.56.44.12*") {echo $ip >> $resultsFile}
}

Open in new window

HTH,
Dan
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
David SankovskySenior SysAdminAuthor Commented:
Thanks Dan! That seems to be what I'm looking for, I'll set it to run and see the results tomorrow.
I'll let you know how it went.
0
David SankovskySenior SysAdminAuthor Commented:
Great Script!!
Worked like a charm.
Thanks a lot
0
Dan CraciunIT ConsultantCommented:
You're welcome.

Glad I could help!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.