This topic contains 1 reply, has 2 voices, and was last updated by
August 20, 2018 at 8:46 am #109003ParticipantPoints: 0Rank: Member
Recently been on a CCNA course and apparently I ask waaay to many questions, so I have been given a "fun task" at work. We have quite a few switches, some of them have telnet enabled and others have SSH only. I am trying to figure out, how you would do a search against an IP or a range, whether they have port number 22 and/or 23 enabled?
Been searching, as one does, and found that plink, part of putty, are able to do that via powershell. As I have no skills in powershell or programming at all, I am a little over my head here. I was wondering if any of you might have a clue OR a better idea of achieving this task?
What I am hoping for:
1. able to use an IP range(s) rather than single IP's.
2. ask for ports. ie 22 (SSH) and 23 (telnet).
3. Return an answer if the specific port is using port 23. ie. "Port 23 is open and password is sent in plain text".
4. Return an answer if the specific port is using port 22. ie. "Port 22 is open and I am protected, using SSH".
4.1. If possible, if both ports are open write something like. port 22 and 23 are both open.
5. Return that answer to an output file ie. Excel or something similar.
6. Being lazy, as one is, I would like to do this with minimum effort possible.
Looking forward hearing what you have for me?
August 20, 2018 at 1:17 pm #109028ParticipantPoints: 68Rank: Member
Given that you would prefer an IP range vs a list of IP addresses, I would think the easiest way to do this would be with NMAP – https://nmap.org/.
While – not a pure powershell solution, it is probably simplest. Your command could be something like:
# the -F will to a port scan on the 100 most common ports, the -oX will output the results to xml nmap.exe 192.168.1.1-20 -F -oX outputfile.xml
Once you get your output – SANS has a powershell script that will parse the xml into objects for easier analysis: https://cyber-defense.sans.org/blog/2009/06/11/powershell-script-to-parse-nmap-xml-output
.\Parse-Nmap.ps1 -Path c:\path\to\outputfile.xml | Export-CSV -path c:\path\to\output.csv -notypeinformation
Now, just open the CSV and find where ports 22 or 23 are open.
If you are really looking to accomplish this with JUST powershell, you can use the
cmdlet. From here you can test for specifically ports 22/23 – but it will require more tweaking to get get the IP range, and to output this to :
$ipaddress = '192.168.1.1' # test for ssh Test-NetConnection -ComputerName $ipaddress -Port 22 # test for telnet Test-NetConnection -ComputerName $ipaddress -Port 23
You must be logged in to reply to this topic.