There are two parts to my IP address, the first part is my network address, 192.168.0, the second part is the individual number I get from my $range of numbers. I then open a script block, and create my IP address, and store it in the variable $ip. Therefore, the first time through, $r will be equal to 1. Following the word ForEach, I create a new variable, $r, to hold the individual number from the array. To walk through the array, I use the ForEach command. If it does, I will attempt a connection to Port 80 to see if I find a web server for my printer. After an IP address is created, I ping the address to see if it responds. Of course, I will create them one at a time. Now, I am going to walk through my array of numbers (1.254) and create a whole bunch of IP addresses. It makes the script easier to read and understand. Using the Hungarian Notation is not required, but I think that calling a port $port certainly is. Note I highly recommend using meaningful variables when you write a script-even a quick script such as this. My class A network address is 192.168.0, so I assign that as a value to the $net variable. As I mentioned earlier, I am only interested in Port 80, so I assign that as a value to the variable $port. Therefore, I used the range operator and created an array of numbers that go from 1 to 254. Actually, the only range I needed to create was a range of host addresses for a class A network. So, I needed to create a range of IP addresses. Perhaps one of the cool things about Windows PowerShell is that it permits this sort of ad-hoc solution to be easily created. And like I said in my introduction, it met my need at the time. I think my solution might simply be useful to show something that I could do. I will also admit it is not the fastest solution possible. Create a range of IP addressesįirst I will admit that my solution is not the cleanest solution possible. I simply needed to look for a device listening on Port 80. By using Windows PowerShell, this was actually a pretty simple task. So what to do? I figured it would be easier to write a port scanner. It was this web server that I needed to access so I could make some changes to the way the printer was handling default forms.īut dude, I did not know the IP address, and I did not want to have to rummage around in my network documentation to find the particular printer in question. However, I did know that the printer sets up a web server. Unfortunately, after several networking changes, I did not remember the IP address of my printer. The other day, I needed to access my printer. Microsoft Scripting Guy, Ed Wilson, is here. Summary: Microsoft Scripting Guy, Ed Wilson, talks about creating a port scanner with Windows PowerShell.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |