Friday, November 28, 2008

Super-Sharable, Self-Installing Widget

There are not many people that will appreciate this, but I just finished coding up a widget form that will install itself on other blogger blogs automatically. Then after it's been installed on someone else's blog it contains the same form so that their readers can add the widget. See it in action on my sidebar for the petit elefant. Here's the code:

<form id="supersharingwidget" action="http://www.blogger.com/add-widget" method="post"><!-- This is the beginning of the real widget content /--><a href="http://petitelefant.blogspot.com"><img border="0" src="http://img81.imageshack.us/img81/5783/elefantsc0.gif"/></a><br/>
<div>To add this button to your blog, copy and paste the text below into the HTML/JavaScript page element on your blog or simply press the button below.<br/><textarea onclick="this.select()">&lt;a href="http://petitelefant.blogspot.com"&gt;&lt;img border="0" src="http://img81.imageshack.us/img81/5783/elefantsc0.gif"/&gt;&lt;/a&gt;&lt;br/&gt;</textarea> </div><!-- This is the end of the real widget content /--><input value="http://petitelefant.blogspot.com/" name="infoUrl" type="hidden"/> <input name="widget.title" type="hidden"/> <!-- Do Not Change anything below this line /--><input id="pewc" name="widget.content" type="hidden"/> <input value="&lt;data:content/&gt;" name="widget.template" type="hidden"/> <input style="border: 0px none ; background: rgb(255, 255, 255) url(http://www.blogger.com/img/add/add2blogger_sm_b.gif) repeat scroll center center; width: 104px; height: 17px; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;" value=" " onclick="var wc = (document.getElementById('supersharingwidget').outerHTML)?document.getElementById('supersharingwidget').outerHTML + '<!--endssw/-->':document.getElementById('supersharingwidget').parentNode.innerHTML.match(/<form id=\u0022supersharingwidget\u0022(.|\n)+<\!--endssw\/-->/)[0].toString();document.getElementById('pewc').value = wc" type="submit"/> </form><!--endssw/-->

Tuesday, November 25, 2008

Count Controls in a Page in C#

Here is a simple method I created to count all the controls in a C#.NET page recursively.

int ControlCount( Control parentControl )
{
int current=0;
foreach( Control c in parentControl.Controls )
{
if (c.Controls.Count > 0)
{
current += ControlCount(c);
}
else
{
current++;
}
}
return current;
}

Thursday, November 13, 2008

WOL Wake On LAN

Have a Linksys Router you're trying to get working with WOL?
Wake On LAN
Wake On LAN (Local Area Network, this is your group of computers) is functionality that allows you to turn your computer on by sending a specially built message to it.

If you're a computer geek Wake On LAN is functionality supported either by your motherboard or your operating system and your NIC (Network Interface Card - this is what you use for your Internet Connection) that listens for special packets called Magic Packets that it then uses to power on or wake up from a non-interactive state.

Wake On LAN can wake up windows from sleep (s3) or hibernate (s4) but you're looking for motherboard support if you want to power on your computer from a shut down state (s5).
What are those s numbers?

Magic Packets
Magic Packets are specially formed UDP packets that signal a specific NIC to send a wake command to the computer. The structure of these packets is a 6 byte header (all ones - so FF FF FF FF FF FF in hex) and the MAC address of the computer to be woken up repeated 16 times for a total of 102 bytes.

MAC Address
A MAC address (Media Access Control address) is a special and mostly unique identifier for NIC Cards. Typically it is 6 Bytes long with the first 3 bytes being used to identify the make of the NIC Card and the last 3 bytes being used to identify your specific card. It's important to note that these MAC addresses or Physical addresses are not guaranteed to be unique, or in other words they can be reused.

Finding your MAC Address and Subnet Mask
The first thing you want to do if you're interested in WOL (Wake On LAN) is get some information about your computer. You can do this a couple of ways, through a command prompt, or through Windows Network Connections, and you may need help from another computer on the internet for your external IP address.

First go to Start>Control Panel>Network Connections. There should be a default one named Local Area Connection. Right-click this icon and choose Status. The choose the Support tab. Then click the Details button. Write down your Physical Address (This is your MAC Address) and Subnet Mask.

If you're doing it from a command prompt I'm going to assume you know what one is and how to launch it etc etc. The command you want to type in is ipconfig /all and you will see information about the various NICs installed in your computer. Look for Ethernet adapter Local Area Connection: as this is the default for a windows internet connection and find the Physical Address (something like 00-00-00-00-00-00), and the Subnet Mask (something like 255.255.255.0).

Finding your Internet-Exposed IP Address
The easiest way to do this is to go to http://www.benfinnigan.com/WOL/whatismyip.asp and write down the IP address it returns. There shouldn't be anything else on the page.

Monday, November 10, 2008

WOL - Wake On LAN through Linksys router

Want to learn more about WOL before starting?

How I got my Linksys WRT54G to Broadcast WOL Packets to my LAN
In my particular set up I have a cable modem, piping internet to a VOIP router piping internet to a wireless Linksys WRT54G router piping internet to my machine.



I wanted to be able to turn on my computer at home without having to call my dear wife and ask her to march downstairs and fire it up. Here are the steps that I performed to make it work:
  1. Prep the NIC Card: Start>Control Panel>Network Connections>Local Area Connection>Properties>Configure> Then looked around for Wake Up, Wake On LAN, settings under the advanced tab and made sure that everything was enabled for magic packets.

    Then I went into the power management tab and unchecked the "Allow the computer to turn off this device to save power" checkbox.


  2. Prep the Motherboard: While my computer is booting I see the Dell logo and some text about how to get into settings or BIOS (typically F2 or F10 or F something). Once I was inside the BIOS I looked around for settings in regard to Wake on LAN sometimes abbreviated WOL. I made sure that WOL was enabled.

  3. Prep the Routers: This is where it gets interesting. Linksys doesn't natively support forwarding ports to the broadcast IP of 255 (you get some JavaScript error "IP value is out of range [0 - 254]"), so to get around it you can try one of two methods (they both worked for me):
    1) I used firefox and DOM Inspector to change the value of the IP for port forwarding thereby circumventing the Javasacript validation. You have to have DOMI installed in Firefox, then inspect the page with the port forwarding for applications and gaming, then right-click the value in DOMI, choose edit, and set it to 255. After that is complete just save the settings.



    2) I also tried saving the html page and modifying the form manually. This also worked like a charm. You need to remember to change the action property of the form to prepend the url of the router. If your router was 192.168.1.1 then your form tag might be <form name="portRange" action="http://192.168.1.1/PortRange.tri" method="post"> assuming PortRange.tri was what you orginally found in the form. You also need to change the value of the IP you're forwarding to be 255. This is what my HTML looked like when I was done:
    <input class="num" onblur="check_valid_value(this,0,254,errmsg.err34,this.defaultValue,lanip,networkip,broadcastip)" maxlength="3" size="3" value="255" name="ip1">

    On the VOIP router I just forwarded the port I decided to use as the Linksys WRT54G which forwards to the broadcast on my LAN.

    Wait, what UDP port am I forwarding you ask? It doesn't really matter. Typically WOL is on 7 or 9 but as long as you pick a port that isn't being used by another application (in other words pick something really high) then you're probably just fine.
  4. Test the setup: So, to test the Wake on LAN settings I used this WOL monitor and wrote my own application for sending packets. Why would I write my own packet sender? Because I couldn't find one out there that didn't apply the subnet mask to the IP and broadcast the message. With my setup I wanted the packet to go directly to my VOIP router, so I built my own WOL application. It's pretty simple:

I also added functionality to send the packet every few seconds so that I could power down my machine while I had a remote machine sending packets to me every 60 seconds and see if my machine turned back on. If you don't want the click once installer you can download it from http://www.benfinnigan.com/WOL/WOL.zip Like usual, if you find the app useful, please drop me a line.

If you're having a hard time getting WOL to work for you, then try this forum to get your particular issue sorted out.

Update:05/27/2010
New! I have an Android App available for WoL and WoW. It's called WoL Wake on Lan Wan. Check it out here: http://blog.benfinnigan.com/2010/05/android-market-update-wol-wake-on-lan.html
Download it:




Disclaimer: The views expressed in this blog entry are provided "as-is" with no guarantee expressed or implied. If tweaking this stuff bricks your box or your router I'm not responsible. Any sites I've linked to are not to be construed as an endorsement and I cannot be held responsible for anything that goes on within other internet sites and their products or forums.

Tuesday, November 4, 2008

Where is settings.settings user.config?

Looking for the user.config file used to hold your user-scoped settings.settings? Try looking in %USERPROFILE%\Local Settings\Application Data\(AssemblyCompany from AssemblyInfo.cs if exists)\(exe name_Evidence Type_Evidence Hash)\(AssemblyVersion from AssemblyInfo.cs)\user.config