Showing posts with label apple. Show all posts
Showing posts with label apple. Show all posts

SOCKS proxy over SSH

Here goes a quick and valuable tip people don't usually know, or at least a couple of friends of mine were not aware of. The two keywords will be SOCKS and SSH.

Connecting over to a remote server, one can bypass unauthorized access blocked by usually our network firewall. The most common examples given are restricted access to Facebook, MSN or torrents. We can also have unlimited access to all kinds of contents thanks to the nice sysadmin managing the network who puts no barriers whatsoever, but we may not trust him or the network users to permit unencrypted data flowing openly. Having some way to establish an encrypted connection to a known network who we trust, or distrust less, and tunneling over it would be safer. This is where SOCKS and SSH can be much of helpful!
SOCKS is an Internet protocol that routes network packets between a client and server through a proxy server. -- via Wikipedia
I'm certain as most, if not all, of our daily applications implement themselves some way of proxying (mostly HTTP, HTTPS and SOCKS) or use the system-wide configured network proxy server. Now all we need is a remote and secure server to proxy and tunnel. This is the part where SSH enters:
Secure Shell (SSH) is a network protocol for secure data communication, remote shell services or command execution and other secure network services between two networked computers that it connects via a secure channel over an insecure network: a server and a client (running SSH server and SSH client programs, respectively). -- via Wikipedia
What this means is if we have a SSH-enabled server we can take advantage of it because typically no further configurations or tweaks are needed. Let's take a look at the SSH client manual:

-D [bind_address:]port
Specifies a local ``dynamic'' application-level port forwarding. This works by allocat-
ing a socket to listen to port on the local side, optionally bound to the specified
bind_address. Whenever a connection is made to this port, the connection is forwarded
over the secure channel, and the application protocol is then used to determine where to
connect to from the remote machine. Currently the SOCKS4 and SOCKS5 protocols are sup-
ported, and ssh will act as a SOCKS server. Only root can forward privileged ports.
Dynamic port forwardings can also be specified in the configuration file.
Got it? Great! Let's combine SSH+SOCKS:
ssh -C2qTnN -D <PORT> <USER>@<IP>
I will not provide the details of what each option features - run 'man ssh' and find by yourself. The result is a SOCKS proxy over SSH. Now let's wrap it in a bash script:
#!/bin/bash

if [[ `uname` == 'Darwin' ]]; then
trap " {
echo \"Setting SOCKS proxy down...\" ; \
networksetup -setsocksfirewallproxystate ethernet off ;
networksetup -setsocksfirewallproxystate wi-fi off;
exit 1;
}" ERR INT TERM EXIT

networksetup -setsocksfirewallproxystate ethernet on
networksetup -setsocksfirewallproxystate wi-fi on
fi

ssh -C2qTnN -D 9999 <USER>@<IP>
Replace <USER>@<IP> by your username and IP address. This bash script, in case you are a Mac user, will automatically turn SOCKS on upon execution and turn it off when shutting down (Mac users using an OS X version prior to Lion should replace "wi-fi" by "airport"). Other Unix users (Linux, BSD, etc) should set SOCKS host as "localhost" and SOCKS port "9999" in either your system network configurations or in each application you want to tunnel over.

Apple MacBook Pro 13" battery history


One year has passed since I bought my Apple MacBook Pro 13" (mid 2010) laptop, and at that time I blogged about it. One feature I demanded was good battery capacity - the MBP 13" seemed like a great choice and I did go for it.

By middle of August I discovered coconutBattery, an application that shows the current battery capacity, its designed capacity, and current and maximum charge, as well as age of the laptop, battery load-cycles, temperature and power usage. One additional feature that popped-out right away was the ability to save the maximum battery capacity and as so since August 12, 2010 to today I've recording these statistics with a fully charged battery to later analyze how my laptop's battery health changed over time. That time has just ran out so let's take a quick look over it!

First, data extraction. A config.xsl file was created with the following content:

<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Edited by XMLSpy® -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
<html>
<body>
<h2>My Apple MacBook Pro 13" (mid 2010) battery history</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>Date</th>
<th>Current Capacity</th>
</tr>
<xsl:for-each select="database/object[@type='SAVEDDATA']">
<tr>
<td><xsl:value-of select="attribute[@name='date']" /></td>
<td><xsl:value-of select="attribute[@name='capacity']" /></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Then, I fired up my terminal and ran:
$ xsltproc --nonet config.xsl ~/Library/Application\ Support/coconutBattery/\
coconutBattery.xml | sed 's|\(.*\)% (\(.*\) mAh)|\2|' > battery.html

This generated a battery.html file with 146 records dumped to a HTML table:

(table dump sniped)

And here is a chart of it:



And finally a screenshot of my coconutBattery:

Battery load-cycles is at 58 after one year and one month and a half. Note that the age of my Mac that reads above is 15 months but the accurate age is 13 months (the former is time since manufactured).

Do you also log your battery health over time? Have these kind of data? Please share it with us!

Ended up buying an Apple...

I have an Acer laptop for about 5 years. It includes a generously 512MB of RAM, Intel Centrino 1.6Ghz (M730 processor to be more precise), ATI Mobility Radeon x600 64MB VRAM, 80GB HDD, yada yada yada. The battery is in an awesome shape if we consider the age and the usage I put on it during this time - previously 3 hours fully charged and now around 2 hours, so... I couldn't have asked for better. Nevertheless, the laptop has an 15.4" display and weighs 3Kg with battery plus the charger which I have to take always with me otherwise the battery would ran out quickly. All this factors led me to buy a new laptop with the main features to consider and give more priority on the weight, battery and size. I didn't want to buy again a new 15.4", up to 4 or 5 hours of battery, and weighed laptop. Basically the requirements were: 12" or 13" screen, up to 2Kg, battery that lasted at least 7 or 8 hours (wireless and reasonable screen brightness), 4GB of RAM or more, and obviously a "good" brand (Sony, Lenovo, Apple, Dell, and HP were on top of the list), not to mention a decent price I could afford. A few hours/days later I decided to pick an Apple Macbook Pro 13" 2.4GHz, not because of the Mac OS X as some might be imagining by now but because of the hardware itself.

The Apple Macbook Pro 13" I bought Tuesday includes an Intel Core 2 Duo 2.4Ghz, 4GB of 1066MHz DDR3, battery up to 10 hours (wireless and 50% screen brightness), and weighs 2.04KG. It cost me 1.149€ but had an (indirect) discount of 5% plus 10€ on the FNAC client card (costs 5€ per year but worths it since it also gives you other discounts and benefits). Here is a short list of highlights regarding the hardware itself and the Mac OS X operating system which, by the way, I have to mention I have never used it until now:

Pros:
  • Laptop is solid rock and its aluminum unibody makes it truly fresh (I don't fell any heat, except in the fan area where the air flows out obviously, while the Acer laptop is more like a heater than a laptop (I bet I could fry an egg on it));
  • Touchpad pretty flexible e practical;
  • Battery lasts up to 10 hours, meaning I don't have to carry the charger wherever I go;
  • The charger has two cables: the charger with the cable to plug in the laptop and another one to extend the length of the cable to the wall socket. This means for, most of the cases, I can leave that extra cable aside or at home;
  • Auto brightness (think a little and you will find how useful it can be);
  • OS X is functional, intuitive, and has a clean UI overall.
Coins:
  • I'm used to have the Ctrl key switched with the Fn key (something I want to get used);
  • At least for the Portuguese keyboard, the square brackets as well as the curly brackets aren't shown in the keyboard and the key combination for the curly brackets isn't easy and convenient: alt+shift+8 for { and alt+shift+9 for } (keys 8 and 9 are where the parentheses are located at). Imagine how great will it to code, not!
  • No "Cut" on files?!
  • "exit" in the Terminal doesn't close the tab, but logs out and stays there opened;
  • If running the OS in Portuguese, cmd+w doesn't close the tab as expected since the shortcut isn't associated and seems there is no way to do so. If running in English, the shortcut is there and do the job;
  • Expected iChat to support the MSN protocol. Using Adium, which is way better;
  • The file (un-)compressor included by default lacks lots of features such has the capability to uncompress split files. Using BetterZip, but still missing Ark from KDE!
  • People advised me to use VLC instead of QuickTime for watching videos, specially those in HD since it seems the codecs used by QuickTime consumes more CPU than it should and that VLC consumes. I would have installed VLC anyway since I'm already used to it being the best video player out there in my opinion.

For those concerned about my devotion to the FOSS world and specially my openSUSE and KDE eccentricity, than there is nothing to you worry about! I'm still the very same guy you used to know. I just needed a laptop with the features I have stated above and that ended up to be an Apple Macbook. That's it, folks!
top