Tag Archives: OSX

Find all hosts on network with Nmap

To find all pingable hosts on the newtwork you are currently on first find your own ip. In Linux/OSX you can run the command ifconfig (windows uses the ‘ipconfig’ command):

malen@LKGADEFB8:~$ sudo ifconfig
eth0      Link encap:Ethernet  HWaddr 00:1d:7e:ad:ef:b8  
          inet addr:192.168.0.77  Bcast:192.168.0.255  Mask:255.255.255.0
          inet6 addr: fe80::21d:7eff:fead:efb8/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:23647854 errors:0 dropped:83 overruns:0 frame:0
          TX packets:31522391 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:100 
          RX bytes:320343317 (305.5 MiB)  TX bytes:3340057852 (3.1 GiB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:1736 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1736 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:159128 (155.3 KiB)  TX bytes:159128 (155.3 KiB)

You here see your IP at ‘inet addr’ on eth0: 192.168.0.77. To see if there are any other hosts on the 192.168.0.x net use:

nmap -v -sP 192.168.0.1/24

This will ping all hosts on 192.168.0.x and show your result in a list

Host 192.168.0.1 appears to be down.
Host 192.168.0.2 appears to be down.
Host 192.168.0.3 appears to be down.
Host 192.168.0.4 appears to be down.
Host 192.168.0.5 appears to be down.
...
Host Slug (192.168.0.77) appears to be up.
...
Host 192.168.0.250 appears to be down.
Host 192.168.0.251 appears to be down.
Host 192.168.0.252 appears to be down.
Host 192.168.0.253 appears to be down.
Host 192.168.0.254 appears to be down.
Host 192.168.0.255 appears to be down.

Tested on OSX 10.7.4 and Debian Lenny

Example virtual host and .htaccess configuration for Zend application on OSX Lion

I usually work with the backend of web applications so I do not get enough training in setting up virtual hosts, so I thought I better put an example up here. At least to have something to start with.

I use the built in apache server on OSX and I usually put my virtual hosts in the <username>.conf (/private/etc/apache2/users/<username>.conf) where <username> is simply your username 🙂

Example:

<VirtualHost *:80>
        ServerName my.zendapp.com
        DocumentRoot "/Users/<username>/Sites/myzendapp"
        ServerAdmin admin@my.zendapp.com

        <Directory "/Users/<username>/Sites/myzendapp">
                Options Indexes FollowSymLinks
                AllowOverride FileInfo
                Order allow,deny
                Allow from all
        </Directory>

</VirtualHost>

To get my.zendapp.com to work we need to put an entry in the hosts file like this:

##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1       localhost
255.255.255.255 broadcasthost
::1             localhost 
fe80::1%lo0     localhost
127.0.0.1       my.zendapp.com

To reach your new zendapp go to: http://my.zendapp.com/public

If you want to use http://my.zendapp.com instead just add the public part to the DocumentRoot:

DocumentRoot "/Users/<username>/Sites/myzendapp/public"
ServerAdmin admin@my.zendapp.com

and the Directory:

<Directory "/Users/<username>/Sites/myzendapp/public">
                Options Indexes FollowSymLinks


NOTE! Depending on your choice in urls you may need to change the .htaccess (/Users/<username>/Sites/myzendapp/public/.htaccess) file accordingly:

For long url (http://my.zendapp.com/public):

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ /public/index.php [NC,L]

For short url (http://my.zendapp.com):

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ /index.php [NC,L]

Tested on OSX 10.7.4 and Zend Framework 1.10.8

Writing image to SD card on OSX

Since I play around with NSLU2, Raspberry PI’s and other experimental devices I tend to use the dd command quite a lot from time to time. The dd command is very powerful tool and if you make a mistake you vill probably have top work countless hours to get things right again, so that is why I now put this little howto up here

1. First we need to find the “system name” for the SD card

diskutil -list

Example output from my developer machine:

/dev/disk0
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *750.2 GB   disk0
   1:                        EFI                         209.7 MB   disk0s1
   2:                  Apple_HFS Macintosh HD            749.3 GB   disk0s2
   3:                 Apple_Boot Recovery HD             650.0 MB   disk0s3
/dev/disk1
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *2.0 TB     disk1
   1:                        EFI                         209.7 MB   disk1s1
   2:          Apple_CoreStorage                         2.0 TB     disk1s2
   3:                 Apple_Boot Boot OS X               134.2 MB   disk1s3
/dev/disk2
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:                 Apple_HFSX My Book                *2.0 TB     disk2
/dev/disk3
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:     FDisk_partition_scheme                        *7.9 GB     disk3
   1:                 DOS_FAT_32 RASPBMC                 7.9 GB     disk3s1

Here we can see my main drive /dev/disk0, my backup drive /dev/disk1 and /dev/disk2 and at the bottom we have a small disk with only 7,9 GB of space and this is my SD card. This makes the “system name” for my SD card /dev/disk3

2. Now its time to unmount the SD card (needed for the dd command on OSX)

diskutil unmountDisk /dev/disk3

3. And now time for the trick part, writing the image

dd if=raspbmc.img of=/dev/disk3

The tricky part is to get if(input file) and of(output file) option correct. My mnemonic for this it that of is called “overwrite file” instead of “output file”. Makes it easier to remember that the of disk will be overwritten – works for me 🙂

The dd command have no progress bar or anything that tells you how long time is left. This is quite annoying. (A dd operation of a 2g image to a SD card takes 30 minutes on my machine). To remedy this we can use another command pv

dd if=raspbmc.img |pv|dd of=/dev/disk3

This gives us a small progress bar to help us keep track of the dd process

Tested on OSX 10.7