Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS 

Python CGI script to display client's IP address

When run as a cgi script, this will print the client's IP address.

import cgi
import os

print "Content-type: text/html"
print ""

print cgi.escape(os.environ["REMOTE_ADDR"])

Create VIPs on Mac OSX

Virtual IPs are so damn useful it hurts sometimes. On Mac OS X 10.1 and above, they're extremely easy to create:

Create a VIP on the same subnet as the primary interface(netmask must be 0xFFFFFFFF):

# ifconfig en1 inet 192.168.1.130 netmask 255.255.255.255 alias


Create a VIP on a different subnet:

# ifconfig en1 inet 192.168.64.25 netmask 255.255.255.0 alias


(Note: you may have to sub en0 for en1. Use ifconfig -a to find out what interfaces are available)

Now you have another IP that you can bring stuff up on that won't collide with other stuff running on the same port.

This is in no way limited to Rails but we can use it to illustrate. Create a VIP for 192.168.1.150 using the ifconfig command above. Then add a line to your /etc/hosts file as follows:

192.168.1.150  myapp


Now bring Rails up bound to that address on port 80:

$ cd devel/myapp
$ ./script/server -b myapp -p 80


http://myapp/ should now be on Rails.
« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS