Thursday, November 29, 2012

Linksys WAG160N drops connection

The Problem

I own a Linksys WAG160N modem router that I got in Singapore. I really like it since It replaces the need for two separate devices.
For the past couple of months the device used to lose connection every day. Only a restart would reset the device and allow it to make a connection. Yesterday, no matter how many times I restarted the device, I couldn't get it to connect to the internet.

The first problem with the Linksys modem was that looking at the status it seemed that the DSL connection was fine and up.
Linksys WAG160N Status screen

On to checking the log however I saw something different.
Linksys WAG160N Log screen
The Modem would try to connect and loop around "Sending PADI 1... Sending PADI 2... Sending PADI 3... Sending PADI 4... Restart adsl"

I looked around at what the PADI thing was.

PADI stands for PPPoE Active Discovery Initiation and it seems that my Modem cant really initiate.
  

Trying to fix

When I was checking Google for a solution, I found out that many people have the same problem. Most think the internet provider is at fault but since I hate calling tech support and usually they don't help anyway, I connected a spare modem I own using the same cables.
The new modem worked fine so this leads me to the assumption that my Modem\Router is at fault.

First thing to try is restore to Factory Defaults.
That didn't help at all I received the same results.

Next thing I tried is to upgrade to the latest firmware.
For some reason I've noticed that a lot of people looking to upgrade the firmware, couldn't find the download link, here: http://homesupport.cisco.com/en-eu/support/gateways/WAG160N/download
The upgrade itself is pritty simple, just download the file, unzip, go to the Firmware Upgrade screen under Administration, choose the BIN file and click upgrade.

Linksys WAG160N Firmware upgrade screen
I am however sad to say, upgrading the firmware didn't help as well.

Current Solution

I had to go back to my spare Modem in order to get an internet connection however I still need to set up a network for the rest of my devices.
Hoping that the Linksys WAG160N Router part is still operational, I set up one of it's ethernet ports as a WAN port and set it up as a dialer as well.


The lucky part was I got My whole network back up. The downside is that I have two devices to connect instead of one.

Any ideas on how to fix the Linksys WAG160N Modem would be appreciated.




Friday, November 16, 2012

Capture an Entire Web Page in a C# Console Application

Its fairly simple to incorporate a browser object into your .Net Windows Forms application.
Just by adding the WebBrowser Object you get the ability to display rich HTML files or browse to websites from your application.
Most programmers also notice the DrawToBitmap functions that enables you to capture the browser window and save it as an image.

A few problems almost always arise here are their solutions:

I cant find the DrawToBitmap function in the Intelisence

DrawToBitmap is part of the WebBrowserBase class. The WebBrowser class inherits from WebBrowserBase and so inherits the DrawToBitmap function.
http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowserbase.drawtobitmap.aspx



DrawToBitmap does not work correctly or produces a blank image

A common mistake is to write your capture code this way:


In order to capture the page one must wait for the page to load.
The way to implement is register to the WebBrowserDocumentCompletedEventHandler .
This way an event will fire when the web page will finish loading and you will be free to capture the image.

The capture doesn't capture the whole web page.

The drawToBitmap function only capturs the image displayed on the browser itself.
In order to capture the whole web page you must make sure that it is all visible.
The way I do it is by resizing the browser to match the scroll bars which almost always match the size of the page itself.

How can I capture the page with out the scroll bars

This one is a simple fix.
Just set the browsers ScrollBarsEnabled property to false.

Putting it all together, you get the following code:



Those were the basics to capture or convert a web page to an image in C# Forms but what if I want the ability to capture a web page from a console application ?

First we'll need to add some missing reference that aren't included by default:

using System.Windows.Forms;
using System.Web;
using System.Drawing;
using System.Threading; 



The next thing you'll probably notice is that when trying to run the same code that worked on a windows form you get "the current thread is not in a single-threaded apartment" exception.
A Google  search will reveal a simple solution, run the browser on a separate thread and set the threads apartment state as a single state apartment. This should stop the exception your seeing but will not fix all the problems.
The DocumentCompleted event we used will not fire up.

Since we are using an ActiveX compnent (The WebBrowser), to fix the issue,We have to create an STA thread that pumps a message loop.

 public void Capture()
        {
            var th = new Thread(() =>
            {
                browser = new WebBrowser();
                browser.DocumentCompleted += wb_DocumentCompleted;
                browser.Navigate(CaptureURL);
                Application.Run();
            });
            th.SetApartmentState(ApartmentState.STA);
            th.Start();
        }


To Sum it all up, I've created a project at codeplex, saving a screen capture of a webpage from a console application https://capturewebpage.codeplex.com/.
Download link is: https://capturewebpage.codeplex.com/downloads/get/533683
Feel free to download the project or leave comments.

Saturday, November 10, 2012

Running a .Net 3.5 Framework on Windows 8

If you try to run a .Net 3.5 Framework application on Windows 8 you might receive an error.
When Googling, I found a fix from Microsoft (http://msdn.microsoft.com/en-us/library/hh506443.aspx)
The thing is you must enable version 3.5 on your computer to make it work and the good news its pretty simple just add it from the Control Panel.

In Control Panel, choose Programs and Features.
Choose Turn Windows features on or off.
Now select the Microsoft .NET Framework 3.5.1 check box.
Click OK, Your done.

Windows 8 Control Panel





Thursday, November 8, 2012

DarkNet - Part 3 - Installing Tor on Android

Installing Tor On Android and IOS

DarkNet - Part 3

 Installing Tor On Android

I love my Android devices and they are my constant companions. That is the reason I wanted to setup Tor on the device as well (To be specific, on my nexus 7 :-) )
You basically just need to go to the market and download 2 apps.
Orbot and Orweb.

Orbot: Tor on Android , is part of the Tor project and is the official port of Tor to the Android platform. This will set up the Tor proxy chain for you. All you need to do is press for a few seconds on the big power icon in the center of the screen, until it turns green.



It does include a few settings that you can play with to set it up to work with all your apps and services (via transparent proxy) but you need to have a rooted device with Superuser privileges.

If you don't have root, you'll need to work with Orbot-enabled apps like Firefox or I personally recommend Orweb.


Orweb is a specialized browser to be used with Orbot.
The best thing about it is that it is pre-configured to work with Orbot.
Once Orbot is running all you need to do is run Orweb and you set to venture into the DarkNet.

 Installing Tor On IOS

Now I have to give credit to Apple. They make great stuff and have a lot of great developers supporting them.
One of the developers is Mike Tigas.
Mike developed "Onion Browser" which can be found on iTunes for 0.99$
Whats cool about the app is that it combines both the browser and the Tor network setup so you don't really have to do anything else.




Its really that simple, Check it out.

Check out more posts about the DarkNet from the main post http://www.codebetweenthelines.com/2012/10/darknet-part-1-what-is-darknet.html