Skip to content

Instantly share code, notes, and snippets.

@jpauli
Last active December 21, 2015 01:49
Show Gist options
  • Select an option

  • Save jpauli/6230757 to your computer and use it in GitHub Desktop.

Select an option

Save jpauli/6230757 to your computer and use it in GitHub Desktop.
libpcap embedding into PHP
<?php
$r = phpcap_create('eth0', PHPCAP_DEV_PROMISC);
phpcap_dispatch($r, function($packet) {
$unpack = unpack('H12macdest/H12macsrc/H4ethtype/H24/a4ipsrc/a4ipdest',$packet);
printf("Got a packet, from %s(%s) to %s(%s)\n",
inet_ntop($unpack['ipsrc']),
$unpack['macsrc'],
inet_ntop($unpack['ipdest']),
$unpack['macdest']);
}
, 3 );
/*
Got a packet, from 192.168.35.171(b499ba567e00) to 157.156.123.81(00090f090005)
Got a packet, from 157.156.123.81(00090f090005) to 192.168.35.171(b499ba567e00)
Got a packet, from 192.168.35.171(b499ba567e00) to 157.156.123.81(00090f090005)
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment