Run a HTTP server in any folder (Mac)

Use this one-liner to serve any directory on Mac on the local network. Navigate to the directory in the terminal first.

python -m SimpleHTTPServer 8000

You can also leave the port out so that it uses the default port 80.

Now, in a browser, type in the below to access the directory files.

http://localhost:8000

Use CTRL+C to end.

If other devices on the local network want to access, replace localhost with your local ip e.g. below:

http://192.168.0.14:8000

Screen Shot 2016-07-16 at 23.15.23

How to stream videos from your Mac or Linux on Smart TVs

Okay, since getting a 50″ Samsung Smart TV, I wanted to be able to stream existing videos from my Mac on the TV. Where do I start? Search for apps? Not helpful. Chromecast is the easiest and cheapest solution but its £35 and as a bit of an IT nerd, I would not go for that option. So, instead I came up with serving files via apache and php to stream. This is not the most convenient way as we will need to be editing file names every time we need a new movie added (which isn’t too bad) but I think would help many like me.

I assume the readers here are somewhat capable of editing configs, Apache and virtual hosts, terminal etc. Pop in any questions below if something is missing or still doesn’t work after these steps.

Checks

System

A Mac/ Linux system with Apache/ PHP (This is already built in on Macs)

Check if Apache works

sudo apachectl start

and in your browser, paste the below. This should display the page below.

http://localhost

localhost
If you don’t see this, that means we’ll need to fix Apache with some help from the section further down. But if it works, follow these next steps to continue.

Steps

1.Make a directory for our new files via terminal

sudo mkdir ~/Sites

2.Create a new user config (You can use the Mac user account short name)

sudo vi /etc/apache2/users/username.conf

3.Paste the following lines into the file and save + quit

<Directory "/Users/*/Sites/">
Options Indexes MultiViews FollowSymLinks AllowOverride All
Require all granted

4.Now enable this user directory to serve files

Note: Take a backup of the httpd.conf file before editing.

cp /etc/apache2/httpd.conf /etc/apache2/httpd.conf.bak
sudo vi /etc/apache2/httpd.conf

5.Uncomment the lines below if they aren’t (Find the block by searching for “userdir”)

LoadModule userdir_module libexec/apache2/mod_userdir.so
LoadModule alias_module libexec/apache2/mod_alias.so
LoadModule rewrite_module libexec/apache2/mod_rewrite.so
LoadModule php5_module libexec/apache2/libphp5.so

Screen Shot 2016-03-20 at 08.49.03

6.Final change to be made

sudo vi /etc/apache2/extra/httpd-userdir.conf

Uncomment the following line in this file, save and quit.

Include /private/etc/apache2/users/*.conf

7.Restart Apache

sudo apachectl restart

Embed HTML5 Video

Now that our servers are working fine and the new directory from step 1 is being served, we need to put some html files in here to access the video we will be embedding. Smart TV’s do not usually support streaming video on their inbuilt ‘browsers’ but can ‘play’ html5 content.

Assumptions

Video file you will be serving:

Daredevil.mp4

Video and HTML File location:

/Users/username/Sites

HTML file name:

daredevil.html

Steps

1.Create html file in the ~/Sites directory and paste this code in and save.

<html>

<body>

<p3 style ="color:Black;font-family:papyrus"><center><b>Daredevil HD</b></center></p3>

<center>

<video width="640" controls> <source src="/Users/username/Sites/Daredevil.mp4" type="video/mp4"> </video> </center>

</body> </html>

2.Check on browser (This is what you should see on the Smart TV)

Type in the following address and you should see a page as below

http://localhost/~username/daredevil.html

Screen Shot 2016-03-20 at 09.31.57

Fixing Apache

Unless you’ve broken the configs. If you have, follow steps here to fix your Apache configs and start over from Step1 above. This site also provides a default copy of the httpd.conf file which can be used to start clean.

Note: Create backups of all files that you will be editing/ replacing.

 

 

TCPDUMP – Tips

As I do my MSc Project with some tools including TCPDump, I decided to post some tips on using TCPDump.

First things first – some commands.

Basic command to capture traffic on a given interface (e.g. eth0)

tcpdump tcp -i eth0 -w capture.log

In this instance, traffic on eth0 will be captured and saved to a file called capture.log

if you intend to export this log to Excel as a CSV file which is a little tricky, Wireshark for the rescue!

Open the log file in Wireshark -> File -> Export Packet Dissections -> Export as CSV

Make sure that you also add the .csv at the end of the filename regardless of it being saved as CSV. Now, the file should open in Excel.

All traffic on an interface

tcpdump -i eth0

Specified number of packets

tcpdump -c 20 -i eth0

-c specifies the number of packets

To display MAC address in the capture

 tcpdump -e -i eth0

For a timed capture on TCPDump

tcpdump all -G 15 -W 1 -w myfile_tcp_15secs -i eth0 

The ‘–G 15’ defines the time period for TCPDump to capture

The ‘-w’ writes to file as named in to location of current directory

The ‘–W’ is the number of iterations the capture will occur

Leave your comments

Thanks 🙂

Software Defined Networking: Controllers

This is a quick tip to efficiently compare SDN simulators if that’s part of your research. I have been researching some controllers and their performance recently and thought I would share the clutter and hassle free tip to test these controllers’ performance. I have paused WireShark in the background which will be used to monitor traffic of whatever type I plan to monitor. I am using controllers OpenDaylight, RYU and ONOS to compare.

  • Open a terminal window for Mininet simulation and name it as appropriate
  • Open one each for the controllers and name them too
  • Start with one controller (run it using the commands specific for them)
  • Simulate a communication on Mininet (e.g. Ping), capture ICMP packets on WireShark for analysis
  • Next, stop the controller and start the next one; simulate a communication instance on Mininet and capture ICMP for analysis. Repeat this for all controllers
  • Depending on how you require the statistics to be visualised, choose an option (e.g. IO Graph on WireShark)

Any questions? comment below and I will try to answer.

SDN Controller Big Picture