2009-08-20 12:21

To know the IP address you use to go out on the Internet, you can use a site like http://www.whatismyip.com

In text mode with no Web browser, it’s a bit more complicated. You can use the following command:

wget --user-agent="Mozilla/5.0" -O - http://www.whatismyip.com 2>/dev/null | grep -o "Your IP Address Is: [0-9.]*"

We have to simulate a real browser, or the site refuses us.

UPDATE 14/01/2010

To find your external IP address, an even more elegant way:

dig +short myip.opendns.com @resolver1.opendns.com

UPDATE 06/05/2010

The best way:

curl icanhazip.com

http://www.commandlinefu.com/commands/view/2966/return-external-ip

2009-08-20 12:21 · Tags: ,
2009-08-10 10:28

When printing an image under Gnome (Eye of Gnome or eog), I did’nt find how to put the page in landscape mode.

Solution: before printing, just rotate the image in eog, then print the image.

2009-08-10 10:28 · Tags: ,
2009-08-03 14:20

If you discover lots of ssh connection tries in your /var/log/auth.log (bots testing users/passwords), you have to do something.

The simpler is to use an IP restriction rule in your iptables firewall, or in /etc/hosts.deny

If you don’t want or can’t use this restriction, use Fail2ban:

aptitude install fail2ban

The default install blocks SSH connection tries.

You can tune the config a bit or activate Fail2ban for other services. Example:

vi /etc/fail2ban/jail.conf
bantime  = 86400
maxretry = 10 # pour ssh
enabled  = true # pour vsftpd
maxretry = 10 # pour vsftpd

Then, the iptables -L command gives you all banned IP addresses.

2009-08-03 14:20 · Tags: , ,
2009-07-30 15:46

In the vast majority of cases, http redirections are installed on the http server.
However, the redirection cannot be installed in the http server config in some cases.

Example: mobile phone redirection.
We want to redirect all mobile phones from http://www.mysite.com to http://mobile.mysite.com

The client type is done with the HTTP User-Agent header sent by the browser. Problem: Squid will put in cache only one version of the query to http://www.mysite.com. The response from the cache will probably be the home page, not the 301 redirection.

It’s also possible to configure the HTTP server to add the Vary: User-Agent header to tell Squid to store one version by browser. With this the cache will be split (one cache per browser), lowering a lot the cache efficiency.

Here is the solution:

###################################
# we redirect mobiles to mobile.mysite.com
url_rewrite_program /etc/squid/redirect_mobile.sh

acl symbian browser Symbian
acl iphone browser iP(hone|od)
acl mobile_url dstdomain mobile.monsite.com

url_rewrite_access deny mobile_url
url_rewrite_access allow symbian
url_rewrite_access allow iphone
url_rewrite_access deny all

And the /etc/squid/redirect_mobile.sh script simply contains:

#!/bin/sh
while read line
do
        echo "301:http://mobile.mysite.com"
done

Notes:

  • The mobile detection method is far from being exhaustive. If you know a simple method covering 95% of browsers, I’m interested!
  • With more recent Squid versions (3, 2.HEAD), you can use a better method using internal redirectors.

Links:

2009-07-30 15:46 · Tags: , ,