With the address space for IPv4 practically used up we must migrate to IPv6. I’m already seeing IPv6 type traffic at work and even at home; therefore, I wanted to get a grip on some of the command line tools offered to work with the new protocol. Earlier this week I started using ping6 and issued the following command:
ping6 fe80:0000:1234:5678:abcd:00ef
On Windows and Linux I recieved error messages because I did not specify which NIC to use. Also, I could have left out leading zeros and saved a few keystrokes. The corrected command is shown below:
ping6 fe80::1234:5678:abcd:ef%1 (for Windows)
ping6 fe80::1234:5678:abcd:ef%eth0 (for Linux)
Windows PowerShell
23
Aug 10
Coming to a Computer Near You: IPv6
22
Nov 09
Download a Web Page with Windows PowerShell
This is an example of using Windows PowerShell to download a Web page and print it to the screen.
$url = "http://www.ke5prl.com"
$client = New-Object System.Net.WebClient
$contents = $client.DownloadString($url)
echo $contents
Now while that might be a neat use of technology it is not terribly useful. If we modify the code just a little we can get back callsign information from one of the common Web lookups. For our first modification let’s change the first line to
$url = "http://www.arrl.org/fcc/fcclook.php3?call=ke5prl" and you can substitute your callsign for mine.
Now let’s turn this into a function. By making it into a function we can easily pass different callsigns to the function without changing the code.
function callsign($call){
$url = "http://www.arrl.org/fcc/fcclook.php3?call=" + $call
$client = New-Object System.Net.WebClient
$contents = $client.DownloadString($url)
echo $contents
}
callsign("KE5PRL")
21
Nov 09
Windows PowerShell – Hello World (2)
With Windows PowerShell it is easy to enter a command at the command prompt to return “Hello World!” Part 1 covered how to do that. The code from Part 1 could be saved in a file with a .ps1 extension and it could be executed by calling it from the command prompt. For example, if saved as hello.ps1, the command to call this script would be ./hello.ps1 if you are in the same directory as the file hello.ps1.
If you have installed Windows PowerShell and have not tried running a script then there may be one extra step that you will need to take. It is described in detail at this link at technet.microsoft.com. What this article details I will summarize – the command you will need to enter at the command prompt is:
set-executionpolicy remotesigned
and that will allow you to run your script. Use Notepad or some other simple text editor for actually entering the scripts otherwise you will introduce various control characters that cause PowerShell to digitally puke.
Now for a Hello World script with a little more sophistication. Paste this into a file named ‘hello2.ps1′ and remember to use Notepad.
[reflection.assembly]::loadwithpartialname('system.windows.forms')
[system.Windows.Forms.MessageBox]::show('Hello World!')
My reference for this is http://powerscripting.wordpress.com/2008/03/03/one-liner-pop-up-a-message-box/.
After saving that file you can execute it by entering ./hello2.ps1 at the Windows PowerShell prompt if you are in the same directory as hello2.ps1 – otherwise use the entire path to call hello2.ps1. Your pop-up box will resemble the one below.
20
Nov 09
Windows PowerShell – Hello World (1)
Making a program output “Hello World!” is the first program that one typically learns when getting started with a new language. You can read about Hello World in a Wikipedia article entitled Hello world program.
At the Windows PowerShell command prompt enter the following:
echo "Hello World!"
and hit enter. That’s all there is to it. In Part 2 learn how to write a short PowerShell script to display “Hello World!”