<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	
	>
<channel>
	<title>
	Comments on: How to Code a Network Packet Sniffer in PHP	</title>
	<atom:link href="https://www.binarytides.com/code-a-packet-sniffer-in-php/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.binarytides.com/code-a-packet-sniffer-in-php/</link>
	<description>News, Technology, Entertainment and more</description>
	<lastBuildDate>Fri, 04 Mar 2022 07:38:54 +0000</lastBuildDate>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.2</generator>
	<item>
		<title>
		By: Volker		</title>
		<link>https://www.binarytides.com/code-a-packet-sniffer-in-php/comment-page-1/#comment-333578</link>

		<dc:creator><![CDATA[Volker]]></dc:creator>
		<pubDate>Fri, 04 Mar 2022 07:38:54 +0000</pubDate>
		<guid isPermaLink="false">http://www.binarytides.com/blog/?p=986#comment-333578</guid>

					<description><![CDATA[Check it out!
SO_BINDTODEVICE =&#062; https://bugs.php.net/bug.php?id=63472]]></description>
			<content:encoded><![CDATA[<p>Check it out!<br />
SO_BINDTODEVICE =&gt; <a href="https://bugs.php.net/bug.php?id=63472" rel="nofollow ugc">https://bugs.php.net/bug.php?id=63472</a></p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: AnonymousXuser264		</title>
		<link>https://www.binarytides.com/code-a-packet-sniffer-in-php/comment-page-1/#comment-197318</link>

		<dc:creator><![CDATA[AnonymousXuser264]]></dc:creator>
		<pubDate>Sun, 19 May 2019 11:50:21 +0000</pubDate>
		<guid isPermaLink="false">http://www.binarytides.com/blog/?p=986#comment-197318</guid>

					<description><![CDATA[Hi,
I saw the comments on problematic receiving raw socket headers, But the comments &#038; replies seemed pretty much out-of subject. IS there any solution for receiving raw socket headers using php??
Already tried in administrate mode, but i am getting no response (not even errors, after setting error_reporting(E_ALL) ). 

Any solutions??]]></description>
			<content:encoded><![CDATA[<p>Hi,<br />
I saw the comments on problematic receiving raw socket headers, But the comments &amp; replies seemed pretty much out-of subject. IS there any solution for receiving raw socket headers using php??<br />
Already tried in administrate mode, but i am getting no response (not even errors, after setting error_reporting(E_ALL) ). </p>
<p>Any solutions??</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: WJ		</title>
		<link>https://www.binarytides.com/code-a-packet-sniffer-in-php/comment-page-1/#comment-134672</link>

		<dc:creator><![CDATA[WJ]]></dc:creator>
		<pubDate>Wed, 11 Oct 2017 09:10:58 +0000</pubDate>
		<guid isPermaLink="false">http://www.binarytides.com/blog/?p=986#comment-134672</guid>

					<description><![CDATA[Hi, Sir.
This PHP script only presents the received packets.
How to present the sent packets?]]></description>
			<content:encoded><![CDATA[<p>Hi, Sir.<br />
This PHP script only presents the received packets.<br />
How to present the sent packets?</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Jerome		</title>
		<link>https://www.binarytides.com/code-a-packet-sniffer-in-php/comment-page-1/#comment-65947</link>

		<dc:creator><![CDATA[Jerome]]></dc:creator>
		<pubDate>Fri, 24 Jan 2014 20:35:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.binarytides.com/blog/?p=986#comment-65947</guid>

					<description><![CDATA[Hi Silver moon,

I tried your PHP sniffer for TCP connections and it works fine.
I would like to get a PHP sniffer to be able to get IGMP messages (not data) : like IGMP join, leave, issued on 224.0.0.22 but other IGMP messages as well.

So I modified your code this way :

$prot = getprotobyname(&#039;igmp&#039;);
echo &quot;protocole : $protn&quot;;
$socket = socket_create(AF_INET , SOCK_RAW , $prot);
$address = &#039;224.0.0.22&#039;;
$tab_mcast = array(&quot;group&quot; =&#062; $address, &quot;interface&quot; =&#062; 0);
socket_set_option($sock, getprotobyname(&#039;ip&#039;), MCAST_JOIN_GROUP, $tab_mcast);

if($socket)
{
    echo &quot;Starting sniffing...n&quot;;
    while(true)
    {
        //Start receiving on the raw socket
        socket_recvfrom ( $socket , $buf , 65536 , 0 );


....


I receive some data but at this time I did not code IP/IGMP packet decoding (I lack information about its structure), and I only get some &quot;0&quot; when transcoding incoming buffer to hexadecimal.
Can you tell me if I am right with this code or would I have to change something ?



Thanks,


Jerome]]></description>
			<content:encoded><![CDATA[<p>Hi Silver moon,</p>
<p>I tried your PHP sniffer for TCP connections and it works fine.<br />
I would like to get a PHP sniffer to be able to get IGMP messages (not data) : like IGMP join, leave, issued on 224.0.0.22 but other IGMP messages as well.</p>
<p>So I modified your code this way :</p>
<p>$prot = getprotobyname(&#8216;igmp&#8217;);<br />
echo &#8220;protocole : $protn&#8221;;<br />
$socket = socket_create(AF_INET , SOCK_RAW , $prot);<br />
$address = &#8216;224.0.0.22&#8217;;<br />
$tab_mcast = array(&#8220;group&#8221; =&gt; $address, &#8220;interface&#8221; =&gt; 0);<br />
socket_set_option($sock, getprotobyname(&#8216;ip&#8217;), MCAST_JOIN_GROUP, $tab_mcast);</p>
<p>if($socket)<br />
{<br />
    echo &#8220;Starting sniffing&#8230;n&#8221;;<br />
    while(true)<br />
    {<br />
        //Start receiving on the raw socket<br />
        socket_recvfrom ( $socket , $buf , 65536 , 0 );</p>
<p>&#8230;.</p>
<p>I receive some data but at this time I did not code IP/IGMP packet decoding (I lack information about its structure), and I only get some &#8220;0&#8221; when transcoding incoming buffer to hexadecimal.<br />
Can you tell me if I am right with this code or would I have to change something ?</p>
<p>Thanks,</p>
<p>Jerome</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: shubham		</title>
		<link>https://www.binarytides.com/code-a-packet-sniffer-in-php/comment-page-1/#comment-64994</link>

		<dc:creator><![CDATA[shubham]]></dc:creator>
		<pubDate>Tue, 19 Mar 2013 10:18:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.binarytides.com/blog/?p=986#comment-64994</guid>

					<description><![CDATA[Call-time pass-by-reference has been removed]]></description>
			<content:encoded><![CDATA[<p>Call-time pass-by-reference has been removed</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Silver Moon		</title>
		<link>https://www.binarytides.com/code-a-packet-sniffer-in-php/comment-page-1/#comment-34246</link>

		<dc:creator><![CDATA[Silver Moon]]></dc:creator>
		<pubDate>Mon, 23 Jul 2012 05:16:59 +0000</pubDate>
		<guid isPermaLink="false">http://www.binarytides.com/blog/?p=986#comment-34246</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.binarytides.com/code-a-packet-sniffer-in-php/comment-page-1/#comment-34182&quot;&gt;smrtl&lt;/a&gt;.

thats good information.
then maybe libpcap has to be tried.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.binarytides.com/code-a-packet-sniffer-in-php/comment-page-1/#comment-34182">smrtl</a>.</p>
<p>thats good information.<br />
then maybe libpcap has to be tried.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: smrtl		</title>
		<link>https://www.binarytides.com/code-a-packet-sniffer-in-php/comment-page-1/#comment-34182</link>

		<dc:creator><![CDATA[smrtl]]></dc:creator>
		<pubDate>Fri, 20 Jul 2012 16:26:25 +0000</pubDate>
		<guid isPermaLink="false">http://www.binarytides.com/blog/?p=986#comment-34182</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.binarytides.com/code-a-packet-sniffer-in-php/comment-page-1/#comment-34179&quot;&gt;Silver Moon&lt;/a&gt;.

Thanks a lot for your quick answer and for the SO_BINDTODEVICE explanation. It gave me access to a brand new field of google results  :)

FYI, the SO_BINDTODEVICE option is not defined on *BSD systems (as Darwin/OS X). There is actually no way (unless the socket is multicast) to determine the interface it is bound to. This seems to be made automatically based on the routing table.

But the reason for getting nothing does not come from a wrong interface problem....

Quoting a post from http://stackoverflow.com/questions/6878603/strange-raw-socket-on-mac-os-x :
&quot;
FreeBSD takes another approach. It *never* passes TCP or UDP packets to raw
sockets. Such packets need to be read directly at the datalink layer by using
libraries like libpcap or the bpf API. It also *never* passes any fragmented 
datagram. Each datagram has to be completeley reassembled before it is passed
to a raw socket.
FreeBSD passes to a raw socket:
    a) every IP datagram with a protocol field that is not registered in
    the kernel
    b) all IGMP packets after kernel finishes processing them
    c) all ICMP packets (except echo request, timestamp request and address
    mask request) after kernel finishes processes them
&quot;

So, bad news, it won&#039;t be possible to make a sniffer in PHP for OS X. Even opening /dev/bpf and try to read from it won&#039;t give any result as the stream must be setup via ioctl calls and I see no way to do that from PHP (without coding an extension).

Any idea is very welcome.

Thanks for your time, nice blog btw !]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.binarytides.com/code-a-packet-sniffer-in-php/comment-page-1/#comment-34179">Silver Moon</a>.</p>
<p>Thanks a lot for your quick answer and for the SO_BINDTODEVICE explanation. It gave me access to a brand new field of google results  :)</p>
<p>FYI, the SO_BINDTODEVICE option is not defined on *BSD systems (as Darwin/OS X). There is actually no way (unless the socket is multicast) to determine the interface it is bound to. This seems to be made automatically based on the routing table.</p>
<p>But the reason for getting nothing does not come from a wrong interface problem&#8230;.</p>
<p>Quoting a post from <a href="http://stackoverflow.com/questions/6878603/strange-raw-socket-on-mac-os-x" rel="nofollow ugc">http://stackoverflow.com/questions/6878603/strange-raw-socket-on-mac-os-x</a> :<br />
&#8221;<br />
FreeBSD takes another approach. It *never* passes TCP or UDP packets to raw<br />
sockets. Such packets need to be read directly at the datalink layer by using<br />
libraries like libpcap or the bpf API. It also *never* passes any fragmented<br />
datagram. Each datagram has to be completeley reassembled before it is passed<br />
to a raw socket.<br />
FreeBSD passes to a raw socket:<br />
    a) every IP datagram with a protocol field that is not registered in<br />
    the kernel<br />
    b) all IGMP packets after kernel finishes processing them<br />
    c) all ICMP packets (except echo request, timestamp request and address<br />
    mask request) after kernel finishes processes them<br />
&#8221;</p>
<p>So, bad news, it won&#8217;t be possible to make a sniffer in PHP for OS X. Even opening /dev/bpf and try to read from it won&#8217;t give any result as the stream must be setup via ioctl calls and I see no way to do that from PHP (without coding an extension).</p>
<p>Any idea is very welcome.</p>
<p>Thanks for your time, nice blog btw !</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Silver Moon		</title>
		<link>https://www.binarytides.com/code-a-packet-sniffer-in-php/comment-page-1/#comment-34179</link>

		<dc:creator><![CDATA[Silver Moon]]></dc:creator>
		<pubDate>Fri, 20 Jul 2012 11:37:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.binarytides.com/blog/?p=986#comment-34179</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.binarytides.com/code-a-packet-sniffer-in-php/comment-page-1/#comment-34176&quot;&gt;smrtl&lt;/a&gt;.

selecting a particular device/interface might not be possible in php.

in c it can be done like this :
setsockopt(sock_raw , SOL_SOCKET , SO_BINDTODEVICE , &quot;eth0&quot; , strlen(&quot;eth0&quot;)+ 1 );

but the documentation at
http://www.php.net/manual/en/function.socket-get-option.php
does not define any such option as SO_BINDTODEVICE

you have to experiment to find whether it can be made to work or not.
I have not tested the code on os x.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.binarytides.com/code-a-packet-sniffer-in-php/comment-page-1/#comment-34176">smrtl</a>.</p>
<p>selecting a particular device/interface might not be possible in php.</p>
<p>in c it can be done like this :<br />
setsockopt(sock_raw , SOL_SOCKET , SO_BINDTODEVICE , &#8220;eth0&#8221; , strlen(&#8220;eth0&#8221;)+ 1 );</p>
<p>but the documentation at<br />
<a href="http://www.php.net/manual/en/function.socket-get-option.php" rel="nofollow ugc">http://www.php.net/manual/en/function.socket-get-option.php</a><br />
does not define any such option as SO_BINDTODEVICE</p>
<p>you have to experiment to find whether it can be made to work or not.<br />
I have not tested the code on os x.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: smrtl		</title>
		<link>https://www.binarytides.com/code-a-packet-sniffer-in-php/comment-page-1/#comment-34176</link>

		<dc:creator><![CDATA[smrtl]]></dc:creator>
		<pubDate>Fri, 20 Jul 2012 11:02:20 +0000</pubDate>
		<guid isPermaLink="false">http://www.binarytides.com/blog/?p=986#comment-34176</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.binarytides.com/code-a-packet-sniffer-in-php/comment-page-1/#comment-34172&quot;&gt;Silver Moon&lt;/a&gt;.

yes the script ran with root privileges through sudo (that&#039;s why i got the start sniffing output and no errors). My question is how do I select the interface ? How do I know with interface the script reads from ?
The problem is not a privilege thing or something related to PHP i think because after compiling and running the same script in C (posted on this blog too) I got the same result. That is everything is set up correctly but no packet is captured...

(note: i&#039;m trying that on an OS X box; PHP 5.3.10 PHP 5.3.10 with Suhosin-Patch (cli))]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.binarytides.com/code-a-packet-sniffer-in-php/comment-page-1/#comment-34172">Silver Moon</a>.</p>
<p>yes the script ran with root privileges through sudo (that&#8217;s why i got the start sniffing output and no errors). My question is how do I select the interface ? How do I know with interface the script reads from ?<br />
The problem is not a privilege thing or something related to PHP i think because after compiling and running the same script in C (posted on this blog too) I got the same result. That is everything is set up correctly but no packet is captured&#8230;</p>
<p>(note: i&#8217;m trying that on an OS X box; PHP 5.3.10 PHP 5.3.10 with Suhosin-Patch (cli))</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Silver Moon		</title>
		<link>https://www.binarytides.com/code-a-packet-sniffer-in-php/comment-page-1/#comment-34172</link>

		<dc:creator><![CDATA[Silver Moon]]></dc:creator>
		<pubDate>Fri, 20 Jul 2012 05:04:20 +0000</pubDate>
		<guid isPermaLink="false">http://www.binarytides.com/blog/?p=986#comment-34172</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.binarytides.com/code-a-packet-sniffer-in-php/comment-page-1/#comment-34165&quot;&gt;smrtl&lt;/a&gt;.

yes, the sniffer will capture packets that are received by the browser.
the program should be run with root privileges (sudo on ubuntu for example).
without root it will not be able to capture packets, because it uses raw sockets which require root privileges.
if the interface is correct, the program should pickup packets.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.binarytides.com/code-a-packet-sniffer-in-php/comment-page-1/#comment-34165">smrtl</a>.</p>
<p>yes, the sniffer will capture packets that are received by the browser.<br />
the program should be run with root privileges (sudo on ubuntu for example).<br />
without root it will not be able to capture packets, because it uses raw sockets which require root privileges.<br />
if the interface is correct, the program should pickup packets.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: smrtl		</title>
		<link>https://www.binarytides.com/code-a-packet-sniffer-in-php/comment-page-1/#comment-34165</link>

		<dc:creator><![CDATA[smrtl]]></dc:creator>
		<pubDate>Thu, 19 Jul 2012 18:19:44 +0000</pubDate>
		<guid isPermaLink="false">http://www.binarytides.com/blog/?p=986#comment-34165</guid>

					<description><![CDATA[Hello sir,

Your code hold my attention so i tried it. While encountering no problem to start it and get the &quot;Starting sniffing...\n&quot; output I did not manage to capture any packet. Am I understanding the thing wrongly if I think this sniffer should be able to capture the packets sent and received when a page is loaded in a browser on my machine ?
I am wondering if the socket may be bound to the wrong interface (like lo0) thus receiving nothing.
Any idea ?

Thanks for sharing this]]></description>
			<content:encoded><![CDATA[<p>Hello sir,</p>
<p>Your code hold my attention so i tried it. While encountering no problem to start it and get the &#8220;Starting sniffing&#8230;\n&#8221; output I did not manage to capture any packet. Am I understanding the thing wrongly if I think this sniffer should be able to capture the packets sent and received when a page is loaded in a browser on my machine ?<br />
I am wondering if the socket may be bound to the wrong interface (like lo0) thus receiving nothing.<br />
Any idea ?</p>
<p>Thanks for sharing this</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Binary Tides		</title>
		<link>https://www.binarytides.com/code-a-packet-sniffer-in-php/comment-page-1/#comment-31625</link>

		<dc:creator><![CDATA[Binary Tides]]></dc:creator>
		<pubDate>Tue, 24 Jan 2012 13:43:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.binarytides.com/blog/?p=986#comment-31625</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.binarytides.com/code-a-packet-sniffer-in-php/comment-page-1/#comment-31622&quot;&gt;Ventre&lt;/a&gt;.

you need php cli to be installed.
Check it with the command &quot;php -v&quot;
It should show something like this :

PHP 5.3.5-1ubuntu7.4 with Suhosin-Patch (cli) (built: Dec 13 2011 18:30:11) 
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
    with Xdebug v2.1.0, Copyright (c) 2002-2010, by Derick Rethans

If it says that command not found then its not installed.

Also this code will work only on Linux.

When running the script provide the full path like :

sudo php /var/htdocs/sniff/sniffer.php

or something similar]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.binarytides.com/code-a-packet-sniffer-in-php/comment-page-1/#comment-31622">Ventre</a>.</p>
<p>you need php cli to be installed.<br />
Check it with the command &#8220;php -v&#8221;<br />
It should show something like this :</p>
<p>PHP 5.3.5-1ubuntu7.4 with Suhosin-Patch (cli) (built: Dec 13 2011 18:30:11)<br />
Copyright (c) 1997-2009 The PHP Group<br />
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies<br />
    with Xdebug v2.1.0, Copyright (c) 2002-2010, by Derick Rethans</p>
<p>If it says that command not found then its not installed.</p>
<p>Also this code will work only on Linux.</p>
<p>When running the script provide the full path like :</p>
<p>sudo php /var/htdocs/sniff/sniffer.php</p>
<p>or something similar</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Ventre		</title>
		<link>https://www.binarytides.com/code-a-packet-sniffer-in-php/comment-page-1/#comment-31622</link>

		<dc:creator><![CDATA[Ventre]]></dc:creator>
		<pubDate>Mon, 23 Jan 2012 18:00:38 +0000</pubDate>
		<guid isPermaLink="false">http://www.binarytides.com/blog/?p=986#comment-31622</guid>

					<description><![CDATA[Thanks for posting this!

I am trying to run it, but can&#039;t create the socket. How do you specify to run it as sudo to view/run the script in a browser (I have it saved in: htdocs/sniff/sniffer.php)?  Your suggestion of &quot;sudo php sniffer.php&quot; from the command line results in a command not found msg. 

Could you please let me know how you are running this awesome script?

Thanks!]]></description>
			<content:encoded><![CDATA[<p>Thanks for posting this!</p>
<p>I am trying to run it, but can&#8217;t create the socket. How do you specify to run it as sudo to view/run the script in a browser (I have it saved in: htdocs/sniff/sniffer.php)?  Your suggestion of &#8220;sudo php sniffer.php&#8221; from the command line results in a command not found msg. </p>
<p>Could you please let me know how you are running this awesome script?</p>
<p>Thanks!</p>
]]></content:encoded>
		
			</item>
	</channel>
</rss>
