Sunday, 27 October 2013

Using Netgear N300 as a modem only

Telkom gives a Netgear N300 modem to their new customers. If you want to use it as a modem only and dial from another router (I use a TP-link router running OpenWRT), follow these easy steps.

Force a 10.0.0.0/8 range IP on your computer (I used 10.0.0.3) and connect to 10.0.0.2 in your browser, the default username and password is usually admin:admin or admin:<blank>.


Then go to 'Setup > Basic Settings', at 'Does Your Internet Connection Require A Login?', set it to 'No', make sure 'Enable' is ticked under 'NAT' and select 'Apply'.


Next go to 'Advanced > WAN Setup', make sure 'Enable PPPoE Relay' is ticked and 'Apply'.


Then go to 'Advanced > LAN Setup', untick 'Use Router as DHCP Server' and 'Apply'.


All that is left is to plug a cable from the modem into the WAN port of your chosen router and dial a PPPoE connection with your Telkom login details.

Setting up iTunes in Linux

I got iTunes working on Ubuntu 13.04 after some googling, but it should work on any Debian based distro. I tested buying and downloading an album and that works. I am not interested in using it as a music player, so you can test that if you want and let me know in a comment.

You will need:

  • iTunes 10 - 32 bit (iTunes 11 works, but cannot connect to the internet, so it is useless and 64 bit does not work)
  • The newest PlayOnLinux (At the time of writing it was version 4.2.1)
  • Wine 1.4.1
iTunes 10.3.1 is available from the Apple support site, so download it (direct dl link).
For the newest PlayOnLinux you will need to add the ppa, instructions are here. There is not an option for Raring Ringtail, Ubuntu 13.04, but I just used the Quantal ppa and that worked fine.
You will need to install wine:
sudo apt-get install wine

Now, run PlayOnLinux and choose 'Install'.


Tick the 'Testing' box and search for iTunes. Select iTunes 10 and press Install.


Follow the steps, they will ask you to select an iTunes installer, select the one you downloaded previously. When you finish, you should have a working iTunes in Linux.

Monday, 23 September 2013

Reset Locked Chinese Tablet

Someone gave me this cheap Chinese tablet:


He forgot the unlock pattern for the tablet and trying to guess it, we got totally locked out. You could still reset it with your google account, but the wifi was off and there is no way to turn it on whilst locked out. So +Nicholas Thompson and I spent some hours figuring out how to reset this tablet.

I found out this tablet uses a rk2918 (Rockchip) SoC (you can open it up or if you know someone else with the same tablet, go to Settings > About Device and check the 'Model Number', mine was 'Full AOSP on Rk29sdk')

First I had to get the tablet into recovery mode. The tablet has no volume buttons, so it has a different key combination from most tablets. So to get into recovery mode make sure the data cable is disconnected, turn off the tablet, then hold the power and menu buttons until the android logo appears. It should now be in recovery mode. Connect the data cable to the computer and run:
lsusb
You will get something like:
Bus 001 Device 011: ID 18d1:d001 Google Inc.
For some reason this is a Google Inc device because of its Vendor ID (list of vendors for those interested). You will need to get adb somewhere, I got it from the android website but it is a big download. You can download just the platform-tools here or run:
wget http://dl.google.com/android/repository/platform-tools_r18.0.1-linux.zip
unzip platform-tools_r18.0.1-linux.zip
cd platform-tools/
You should see a device with the command:
./adb devices
listed as:
???????????? no permissions
Add the tablet's vendor to the udev file to get the correct permissions:
echo 'SUBSYSTEM=="usb", ATTR{idVendor}=="18d1" , MODE="0666", GROUP="plugdev"' >> /etc/udev/rules.d/51-android.rules
disconnect and reconnect the data cables and run ./adb devices again and you should get:
0123456789ABCDEF recovery
To get the tablet info flash mode run:
./adb reboot bootloader
The tablet screen will go black, but it is not off, you will see it if you run lsusb again. It should be listed as something like Bus 001 Device 013: ID 2207:281a. Add this device to the udev rules as well:
echo 'SUBSYSTEM=="usb", ATTR{idVendor}=="2207", MODE="0666", GROUP="plugdev"' >> /etc/udev/rules.d/51-android.rules
For the next step you will need Rockbatchtool. I found some instructions and a linux version here.

You need to install the needed package and build the executable:
wget -O rkflashtool-v2.zip http://forum.xda-developers.com/attachment.php?attachmentid=785592&d=1321547155
unzip rkflashtool-v2.zip
sudo apt-get install libusb-1.0-0-dev
gcc -o rkflashtool rkflashtool.c -lusb-1.0 -O2 -W -Wall -s
Find the tablet's partition table by running:
./rkflashtool r 0x0000 0x2000 >parm
then check the start of this file with a hex dump:
xxd parm | less
mine looked like this:
0000000: 5041 524d 5302 0000 4649 524d 5741 5245  PARMS...FIRMWARE
0000010: 5f56 4552 3a30 2e32 2e33 0d0a 4d41 4348  _VER:0.2.3..MACH
0000020: 494e 455f 4d4f 4445 4c3a 4675 6c6c 2041  INE_MODEL:Full A
0000030: 4f53 5020 6f6e 2052 6b32 3973 646b 200d  OSP on Rk29sdk .
0000040: 0a4d 4143 4849 4e45 5f49 443a 3030 370d  .MACHINE_ID:007.
0000050: 0a4d 414e 5546 4143 5455 5245 523a 524b  .MANUFACTURER:RK
0000060: 3239 5344 4b0d 0a4d 4147 4943 3a20 3078  29SDK..MAGIC: 0x
0000070: 3530 3431 3532 3442 0d0a 4154 4147 3a20  5041524B..ATAG: 
0000080: 3078 3630 3030 3038 3030 0d0a 4d41 4348  0x60000800..MACH
0000090: 494e 453a 2032 3932 390d 0a43 4845 434b  INE: 2929..CHECK
00000a0: 5f4d 4153 4b3a 2030 7838 300d 0a4b 4552  _MASK: 0x80..KER
00000b0: 4e45 4c5f 494d 473a 2030 7836 3034 3038  NEL_IMG: 0x60408
00000c0: 3030 300d 0a43 4d44 4c49 4e45 3a20 636f  000..CMDLINE: co
00000d0: 6e73 6f6c 653d 7474 7953 312c 3131 3532  nsole=ttyS1,1152
00000e0: 3030 6e38 6e20 616e 6472 6f69 6462 6f6f  00n8n androidboo
00000f0: 742e 636f 6e73 6f6c 653d 7474 7953 3120  t.console=ttyS1 
0000100: 696e 6974 3d2f 696e 6974 2069 6e69 7472  init=/init initr
0000110: 643d 3078 3632 3030 3030 3030 2c30 7838  d=0x62000000,0x8
0000120: 3030 3030 3020 6d74 6470 6172 7473 3d72  00000 mtdparts=r
0000130: 6b32 3978 786e 616e 643a 3078 3030 3030  k29xxnand:0x0000
0000140: 3230 3030 4030 7830 3030 3032 3030 3028  2000@0x00002000(
0000150: 6d69 7363 292c 3078 3030 3030 3430 3030  misc),0x00004000
0000160: 4030 7830 3030 3034 3030 3028 6b65 726e  @0x00004000(kern
0000170: 656c 292c 3078 3030 3030 3830 3030 4030  el),0x00008000@0
0000180: 7830 3030 3038 3030 3028 626f 6f74 292c  x00008000(boot),
0000190: 3078 3030 3030 3830 3030 4030 7830 3030  0x00008000@0x000
00001a0: 3130 3030 3028 7265 636f 7665 7279 292c  10000(recovery),
00001b0: 3078 3030 3046 3030 3030 4030 7830 3030  0x000F0000@0x000
00001c0: 3138 3030 3028 6261 636b 7570 292c 3078  18000(backup),0x
00001d0: 3030 3033 6130 3030 4030 7830 3031 3038  0003a000@0x00108
00001e0: 3030 3028 6361 6368 6529 2c30 7830 3031  000(cache),0x001
00001f0: 3030 3030 3040 3078 3030 3134 3230 3030  00000@0x00142000
0000200: 2875 7365 7264 6174 6129 2c30 7830 3030  (userdata),0x000
0000210: 3032 3030 3040 3078 3030 3234 3230 3030  02000@0x00242000
0000220: 286b 7061 6e69 6329 2c30 7830 3030 4536  (kpanic),0x000E6
0000230: 3030 3040 3078 3030 3234 3430 3030 2873  000@0x00244000(s
0000240: 7973 7465 6d29 2c2d 4030 7830 3033 3241  ystem),-@0x0032A
0000250: 3030 3028 7573 6572 290d 0a3b ff43 e300  000(user)..;.C..
The relevant parts are:
0x0003a000@0x00108000(cache) and 0x00100000@0x00142000(userdata).

This means the cache partition has a size of 0x0003a000 and starts at 0x00108000 and the userdata a size of 0x00100000 and starts at 0x00142000.

Firstly backup both these partitions (in case this does not work):
./rkflashtool r 0x108000 0x3a000 >cache_backup
./rkflashtool r 0x142000 0x100000 >userdata_backup
Then overwrite both partitions with 0's:
./rkflashtool w 0x108000 0x3a000 </dev/zero
./rkflashtool w 0x142000 0x100000 </dev/zero
Lastly reboot the tablet with:
./rkflashtool b
The tablet should now boot as though it was factory reset. I went to the settings menu anyway and did another factory reset from there, just in case.

Wednesday, 7 November 2012

Home Network 2: CTWUG

The Network

This post is about the CTWUG setup. I bought all the needed hardware from Scoop and followed the instructions on the CTWUG wiki to get everything working. I then spent a while on their IRC server to find the correct person to connect to, and get an IP range allocated. They allocated 172.18.28.80/29 to me (172.18.28.80-172.18.28.86), with .80 allocated to the wireless radio card and .86 to the MikroTik router. At first I forced IP's and a gateway on each PC on my network, but I wanted a more elegant solution.


The way I decided to go was to put the CTWUG connections on a separate VLAN and to do source and destination NATing.

I connected the MikroTik to port 5 of the TP-LINK router and set that port on a separate VLAN.


Then had to create a separate interface for it with only the VLAN that was just created.


And to get the whole thing working a static route is needed which routes all ctwug traffic (172.18.0.0/16) through the MikroTik.


At this stage I could ping the CTWUG network, but had a problem with the hostname lookups. So under the advanced DHCP options, I entered option 6, which advertises custom DNS servers. And advertised the ctwug DNS server and Telkom DNS server with it. The full command is "6,172.18.1.1,196.43.45.190".


I am now able to access everything on the CTWUG network, but all my devices are behind a masquerade NAT, so I would not be able to access my individual devices from the CTWUG network. I need this if I decide to host a website or any other service on the WUG.

The first part (and I am still looking for a better solution) is to create a few IP aliases so the router responds to ARP requests for those IP's.


And the final part is for the router to actually forward request for those IP's to the correct PC on the local network. For this you need SNAT for outgoing packages and DNAT for incoming packages. I want this to be 1 to 1 NATing, so instead of adding a DNAT and SNAT for each IP, I used the NETMAP iptables option. I first needed to install the iptables-mod-nat-extra package.



I then added two firewall rules to do the NATing. For the destination NAT

iptables -v -t nat -A PREROUTING -i eth0.3 -s 172.18.0.0/16 -d 172.18.28.80/29 -j NETMAP --to 192.168.0.0/29

for the source NAT

iptables -v -t nat -A POSTROUTING -o eth0.3 -s 192.168.0.0/29 -d 172.18.0.0/16 -j NETMAP --to 172.18.28.80/29

This would mean that 192.168.0.1 would be seen as 172.18.28.81 to other people on CTWUG, and similarly up to 192.168.0.6. I also made sure masquerading was enabled (for any IP's not in this range).



That is it! You now have this part of the network:



Torrenting Tip

One problem I still had was that torrents that I wanted to download from CTWUG sometimes used my Internet. The client I use is Transmission and it can use block lists. So I blocked all IP's that are not on the CTWUG network on the Transmission client of the PC I use for my CTWUG torrents.

I did this by adding the lines

other:1.0.0.0-172.17.255.255
other2:172.19.0.0-254.255.255.255

to

~/.config/transmission/blocklists/list.txt

and made sure blocklists were enabled in

~/.config/transmission/settings.json

with the line

"blocklist-enabled": true,

tl;dr
Set up the CTWUG network connection with 1 to 1 NATing and gave a handy torrenting tip.

Sunday, 28 October 2012

Home Network 1: Getting Started

This is the first post about my home network. Before I get to the advanced parts, the basic network first needs to be set up. That is what will be described in this post. For the more advanced sections you will have to wait for the next post.

To understand the workings of my home network, it would be better to start at the end than the beginning. After the last post about my home network you should know how I set up each part of the network in the figure below, as well as how to graph the network traffic per MAC.


So let's back up a little and look at the network from the start.

The Main Router

The central gateway for my network is my TP-LINK router, so this is the first thing that I need to set up. Because my network has many things that it has to do, I want something that gives me a bit more control than the default firmware. I decided to flash the router with OpenWrt, which is a Linux distribution for embedded devices. You can check the list of OpenWRT supported devices on the OpenWrt website to see if your router is supported. They also have detailed instructions on how to flash each of these routers.

When this is done you can ssh into your router or use the web-interface. It should look something like this:


If your computer does not have an IP in the same range as the router (192.168.0.0/16 most of the time) you may need to force one in order to access it.

The Internet and DHCP

The next step is setting up the TP-LINK to dial the internet connection. By default my Telkom Mega 105WR modem dials the internet connection and runs a DHCP server, thus I had to turn both of these off. The way to do this differs for each modem. To dial the internet connection with the TP-Link router, the Telkom modem must be in "Bridge" mode (you will be able to change this under the connection settings, it will be in PPPoE mode) and must be connected to the WAN port of the TP-LINK router. You will need to write down the PAP/CHAP username and password from the modem as this will be needed to dial the connection from the TP-LINK.

Now on the OpenWRT web-interface go to Network > Interfaces > WAN. Set the protocol to PPPoE, enter the username and password. Finally "Save & Apply".


Lastly you will have to set up the DHCP server. I have set it up so my network has the range 192.168.0.0/24, with the router IP being 192.168.0.254.

To do this go to Network > Interfaces > LAN. Set the protocol to "Static address", enter IPv4 address > 192.168.0.254 and IPv4 netmask > 255.255.255.0. Finally "Save & Apply".


At this point you will have this part of the network:


tl;dr
Flashed TP-LINK router with OpenWrt and set up WAN and LAN.

Tuesday, 16 October 2012

A Beginning

Welcome to my blog. This is my first attempt at blogging, so I will see where it goes.
I plan to post about projects that I work on in my free time, as well as some general information about creating an online presence.

I have three general projects I am busy with at the moment. I will give a brief overview of each, but will provide more detail in future posts.

1) Setting up my home network.

I am not talking about just having internet (which is as easy as plugging a cable into a modem that your ISP provides), but something more advanced. A quick overview of the challenge that I am facing: currently I have three different networks that I need to connect to. The Internet, CTWUG (Cape Town Wireless User Group) and the Stellenbosch University network (which is reachable via a VPN or Virtual Private Network). This is all relatively easy to get working on a per device basis (by forcing IP's and dialling a VPN on each pc), but I want this all to work transparently. If I get a new computer or connect to the WiFi on any device, I want to be able to access all these networks without changing any settings or installing any software.

2) Series Renamer

I watch a lot of series. It gets irritating when the files have different naming conventions and as a result episodes are out of order in a list. I decided to write a script which looks at all  your series and renames them with a consistent naming scheme. The script also gets the name of each episode as well as a list of all the episodes that you are missing. The result is something in this form and directory structure:


Psych
└─ Psych S01
      ├─ Psych S01E01 - Pilot.avi
      ├─ Psych S01E02 - Spellingg Bee.avi
      └─ Psych S01E03 - Speak Now or Forever Hold Your Piece.avi



I am currently working on a GUI (Graphical User Interface) for the renamer and finally got it to remain stable while fetching the filelists. Normally the whole thing would just hang while fetching the filelists so I had to implement an additional thread, but this made everything unstable and it kept crashing until I implemented the thread handling correctly - which is a hard thing of you are new to it as I am.

3) The Web

While I do not have very much experience with coding websites, I have tinkered a bit. I can give an outline on how to get started and give some ideas. Some information on acquiring and using a host-name  how to set up a DrupalWordPress or similar site. I am also running a VPS (Virtual Private Server) that I am renting from ThrustVPS and will give some more information on this as well.

tl;dr
This blog is about my projects, including networking, programming and the web.