http snippets

How to inspect HTTP traffic with tcpdump and ngrep

Tagged ngrep, http, tcpdump  Languages bash

ngrep

ngrep is one alternative to tcpdump:

$ sudo ngrep -q -d lo0 -W byline host localhost and dst port 3002

The command will listen to interface lo0 and print all traffic destined for localhost port 3002.

tcpdump

Write traffic on port 80 (HTTP) to a file. Rotate log file after 10Mb. Keep 5 files.

$ sudo tcpdump port 80 -n -i any -w /tmp/traffic -p -C 10 -W 5 -s 1500

This gist shows how to monitor HTTP requests.

On OSX remember to install tcpdump with brew:

$ brew install tcpdump

HTTP parameter named "action" is reserved in Rails

Tagged action, parameter, http, reserved, rails  Languages ruby

The “action” and “controller” HTTP parameters are reserved in Rails, so you cannot access them through the params object.

To access them you can do this:

def index
  if request.post?
    request.POST['action']
  else
    request.GET['action']
  end
end

HTTP and HTTPS client example in Racket

Tagged https, racket, client, http  Languages racket
; HTTP example
(require net/http-client)
(http-sendrecv "google.com" "/" #:port 80)

; HTTPS example
(require net/http-client)
(http-sendrecv "google.com" "/" #:port 443 #:ssl? 'tls)