Code Blog

Displaying 11-15 of 17 results.
2016/09/05 MacOSX,Network,iOS


PortTCP or UDPService or Protocol NameRFCService NameUsed by / Additional information
192 UDP OSU Network Monitoring System - osu-nms AirPort Base Station PPP status or discovery (certain configurations), AirPort Admin Utility, AirPort Express Assistant

UDP Wi-Fi Calling 5996 IKEv2 Wi-Fi Calling
515 TCP Line Printer (LPR), Line Printer Daemon (LPD) - printer Used for printing to a network printer, Printer Sharing in Mac OS X
554 TCP/UDP Real Time Streaming Protocol (RTSP) 2326 rtsp QuickTime Streaming Server (QTSS), streaming media players, AirPlay
631 TCP Internet Printing Protocol (IPP) 2910 ipp Mac OS X Printer Sharing, Printing to many common printers
1900 UDP SSDP - ssdp Bonjour, Back to My Mac
3689 TCP Digital Audio Access Protocol (DAAP) - daap iTunes Music Sharing, AirPlay



Bonjour is Apple's implementation of zero-configuration networking (zeroconf), a group of technologies that includes service discovery, address assignment, and hostname resolution. Bonjour locates devices such as printers, other computers, and the services that those devices offer on a local network using multicast Domain Name System (mDNS) service records.


AirDrop is a handy method of sharing data with any Mac equipped with OS X Lion (or later) and a Wi-Fi connection that supports PAN (Personal Area Networking). PAN is a somewhat recent standard that has been added to the Wi-Fi alphabet soup of capabilities. The idea of PAN is that two or more devices that come within range of each other can communicate using a peer-to-peer connection method. Apple's implementation of AirDrop relies on WiFi chipsets that have built-in PAN support. This reliance on hardware-based PAN capabilities in WiFi chipsets has the unfortunate consequences of limiting the use of AirDrop to Macs from late 2008 or later.

AirDrop uses Apple's Bonjour technology to listen in on a WiFi connection for another Mac to announce AirDrop capabilities. It seems AirDrop will announce itself over any available network connection, but when AirDrop listens, it only pays attention to Wi-Fi connections, even if AirDrop announcements are present on other network interfaces.

defaults write BrowseAllInterfaces 1

// Enable AirDrop Over Any Network Connection

To use AirDrop, both Bluetooth and Wi-Fi must be turned on. AirDrop uses Bluetooth to locate other AirDrop-enabled devices nearby and uses the faster Wi-Fi network to transfer the files. Because AirDrop uses Bluetooth, it adheres to a common Bluetooth range, which requires devices to be within 33 feet/10 meters of each other.

When AirDrop is enabled, it triggers Bluetooth to look for other AirDrop-enabled iOS devices that are in the area. This process is similar to pairing your iPhone with your car’s Bluetooth system. The devices “advertise” that they are open for business, and if they are within range of each other, then they start the connection process. Once the connection is made, a simple device-to-device Wi-Fi link, called Wi-Fi Direct, is created between the two. The Wi-Fi Direct link can be created even if you are in the middle of nowhere, without a Wi-Fi network. So, you get the fast file transfer speed of Wi-Fi without a router or an internet connection.

To limit who can see your device to only the people in your Contacts, you’ll need to sign in to iCloud with your Apple ID.

Only some Apple iOS devices have both Bluetooth 4.0 and Wi-Fi Direct capabilities: i.e. iPhone 5 (and later) iPad (4th generation and later). iOS 8 and OS X Yosemite (10.10) allowed the use of AirDrop between Macs and iOS devices.

I had some problems to get the iphone/macbook AirDrop connection to work. I think the main reason is that I turned on "contact only" on the Macbook. When I use a router with VPN it works good, but not with another router. As the connection is setup via an independent PAN network, the router shouldn't be a factor at all. But maybe for getting the contacts list from iCloud it is?

Some other tips I found online for troubleshooting AirDrop (and Handoff)

  1. Turn off Bluetooth on your Mac
  2. Delete /Library/Preferences/
  3. Turn Bluetooth back on 

 In your WiFi router, change it from Wireless Encryption WPA2 (Mixed) to Wireless Encryption WPA2(AES).


AirDrop information from:

See full port numbers listing at



2016/08/11 MacOSX,iOS

I've got a lot of trouble accessing Apple's servers from work/home here in Shanghai. Maybe the servers are too busy, but in any case, most of the time the iTunes update operation (downloading the file) disconnects before it's completed. The same happens often with XCode simulator downloads btw.

So a better way is to download the firmware first and then install it via iTunes. You need to first check which firmware file to download for the iPhone, it is either GSM or GLOBAL (CDMA + GSM) version. You can check the model number at the back of the phone and just google it to find out which type you have got.

In my case it is: iPhone 5s Model A1533 (GSM)
iPhone 5s is encoded as model nr 6 for the IPSW filename, where 6.1 is for GSM and 6.2 is for GLOBAL.

Next step is to download the IPSW file, for example:,1_9.3.2_13F69_Restore.ipsw

9.3.4 is a jailbreak security patch, so I rather just install 9.3.2.

Install IPSW on iPhone

Always make a backup before upgrading iOS.

  1. Connect your iPhone to your computer
  2. Select the device in iTunes
  3. Hold down the "Option" key and click on "Update" ("Shift" key on Windows)
  4. Select the IPSW file you downloaded
  5. iOS installation runs as normal

You can also click on "Restore" and select an IPSW file but this will lose all existing files and settings on the iPhone.

2016/07/01 MacOSX

I've been trying to find a solution to stop my cat from turning off my Macbook Air. I normally leave the computer in the screen saver / login screen mode so that the cat can't mess up any open documents etc (this happened before). However, sometimes when I get back the computer has been completely powered off!

So obviously just running the screen saver won't be enough, instead I need a way to disable the power button on the keyboard. Unfortunately Apple hasn't designed their system with this in mind.

I found some tips at for protecting the keyboard from one's cat but that doesn't really work for me. It is more about locking down the keyboard from unintentional input, but if I turn on the screensaver (I use a hot corner with my mouse to start the screensaver btw) before leaving the computer I already don't have that problem. The power button is still active though.


Next I downloaded and installed Karabiner ( which is a free tool for remapping the Mac keyboard.


I discovered that Karabiner doesn't remap the power button any longer! (I'm running 10.11 El Capitan).

Before 10.9 pressing the power button for 1.5 would display this dialog window:

It turns out the way Karabiner remapped the power button was to detect this popup dialog. After Apple changed the behaviour in 10.9 (no popup window) it wasn't any longer possible to intercept it (it is possible to detect the key event but not stopping it from going to sleep).

Turns out this behaviour was disabled in OS X 10.9 but was later added back on as an option in 10.9.2. The following command can restore the old behaviour:

defaults write PowerButtonSleepsSystem -bool NO

Power button old behaviour (from the Apple documentation)

Power button • Tap to turn on your Mac or wake your Mac from sleep.  
• Hold for 1.5 seconds while your Mac is awake to display a dialog asking if you want to restart, sleep, or shut down. If you don't want to wait 1.5 seconds, press Control–Power button or Control–Media Eject  .
• Hold for 5 seconds to force your Mac to turn off.


There is another free tool called PowerKey ( that got broken off from Karabiner to only deal with the power button. I downloaded the code and built it in XCode.


This worked after I changed the deployment target to my current system.

Turns out Karabiner and PowerKey never were able to to what I wanted. It's useful for typing as you can re-map the powerkey to for example a forward delete. But it was never able to totally disable the power button. Maybe I should have realized this earlier, because the power button is the only way to reset / turn off the computer, so it shouldn't really be possible to easily change in software (virus/malware could really mess up the computer).

I found some good information at
Running the following command can unload (totally disable) the internal keyboard kernel extension:

sudo kextunload /System/Library/Extensions/AppleACPIPlatform.kext/Contents/PlugIns/AppleACPIButtons.kext

But even running the command above (you will preferably also need an external keyboard to reload the internal keyboard kernel extension later) will not disable the power button! The power button is the only way to reset the computer so it's actually not part of the internal keyboard. It's a very special key indeed.

In the end it might actually be better to prevent the Mac from sleeping when folding it (so it will keep downloading files or playing a movie etc). Folding the computer will for sure prevent my cat from sitting on the power button. There are some free tools available that does just that (I installed InsomniaX) but I also read some warnings that this may restrict the air flow and overheat the macbook, so this solution is also not without it's own problems. But it is still the best option I could find, as its the only way to actually protecting the power key button (physically protecting it with the screen cover).

Karabiner, PowerKey and InsomniaX are all quite useful pieces of software, so it's worth checking them out.

The new Macbook Pro (still no release date, maybe end of 2016?) is rumoured to have a TouchID function integrated with the power button, which would be great, as that will hopefully prevent my cat from powering off the computer in the future! 

2016/04/01 MacOSX

brew install homebrew/science/octave

 Had some troubles getting the install to work, it never finished and seemed to get caught up in a dependency loop. Tried turning on the verbose flag to get more information of what was going on:

brew install -v homebrew/science/octave

 Next step is verbose and debug mode:

brew install -vd homebrew/science/octave


2016/03/30 MacOSX

Before switching to Mac I used to install Cygwin ( to add some handy Unix command line tools to Windows. As Mac OS X is built from Unix it already comes with a lot of command line tools pre-installed. However, Homebrew ( is a package manager for installing some Unix tools that are missing in Mac OS X. It's also quite interesting that Homebrew used Kickstarter to fund part of its setup costs, see extract below from Wikipedia:

In March 2013, Homebrew successfully completed a Kickstarter campaign to raise funds for servers to test and build formulae and managed to raise £14,859.

Links  Introduction to Homebrew Homebrew Cask extends Homebrew and brings its elegance, simplicity, and speed to OS X applications and large binaries alike. is an online package browser for Homebrew Online search for Homebrew packages

Homebrew typically deals with command line software, normally distributed under an open source licence. brew cask is an extension to brew that allows management of graphical applications through the Cask project. Cask software may have commercial licences.

Useful HomeBrew Packages

wget Command line network downloader

Network exploration tool and security / port scanner

youtube-dl Download Youtube videos
ffmpeg Encode/compress video & music
htop Improved top tool; Scroll process list etc
imagemagick Tool for rendering image files
ack similiar to grep (text finder)
tig git command line interface
awscli AWS command line tools (Amazon hosting)
geoip check where and IP comes from
ccrypt file encryptor
hh shell history browser / searcher
mysql database system
automysqlbackup automates MySQL backups
irssi IRC client

Homebrew are by default installed in /usr/local

To install a package just type "brew install packagename".

I also tried to install "octave" from Homebrew (a free GNU Matlab-clone) but it's GUI is unstable for Mac OS X so I didn't bother too try to get it working in the end (Scilab, another Matlab clone, may be better, see

Youttube-dl commands

youtube-dl -F list all formats
youtube-dl -f 22 download format number 22
youtube-dl -f bestaudio+bestvideo "http://.../watch?v=id automatically choose highest quality for download