{"id":16389312,"url":"https://github.com/marcelog/simplepcap","last_synced_at":"2025-03-23T04:31:35.926Z","repository":{"id":2505682,"uuid":"3480752","full_name":"marcelog/SimplePcap","owner":"marcelog","description":"A mini libpcap adapter in C++, with a php module using SWIG","archived":false,"fork":false,"pushed_at":"2012-06-13T20:14:37.000Z","size":125,"stargazers_count":29,"open_issues_count":2,"forks_count":15,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-01T21:41:41.321Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://marcelog.github.com/articles/swig_php_libpcap_module_c++.html","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/marcelog.png","metadata":{"files":{"readme":"README","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-02-18T20:10:37.000Z","updated_at":"2023-08-25T03:45:45.000Z","dependencies_parsed_at":"2022-08-28T19:00:23.479Z","dependency_job_id":null,"html_url":"https://github.com/marcelog/SimplePcap","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcelog%2FSimplePcap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcelog%2FSimplePcap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcelog%2FSimplePcap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcelog%2FSimplePcap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/marcelog","download_url":"https://codeload.github.com/marcelog/SimplePcap/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244269772,"owners_count":20426295,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-11T04:32:20.004Z","updated_at":"2025-03-23T04:31:35.461Z","avatar_url":"https://github.com/marcelog.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"This is the sourcecode for: http://marcelog.github.com/articles/swig_php_libpcap_module_c++.html\n\nIt is a small C++ wrapper around libpcap, that comes with a SWIG interface file \nfor PHP. So this will in essence, give you access to libpcap from PHP.\n\nCurrently, it can list all devices and sniff packets without using pcap_loop(). It\nuses pcap_next(). You can also inject packets, the wrapper will call pcap_inject().\n\nNOTE: It's very possible that you will need root or administrator privileges\nto sniff an interface. So, beware.\n\nCI\n==\nYou can get a build for linux x86_64 at:\nhttp://ci.marcelog.name:8080/view/C%20C++/?\n\nUSE EXAMPLE\n===========\n\nList all devices\n----------------\nforeach (SimplePcap::findAllDevs() as $name =\u003e $description) {\n    echo \"$name =\u003e $description\\n\";\n}\n\nGetting packets\n---------------\nFirst, get an instance of the SimplePcap class:\n$simplePcap = new SimplePcap($interfaceName, $filter, $snapLen, $timeout);\n\n$interfaceName can be something like \"any\", or \"eth0\".\n$filter is a libpcap filter, like \"port 80\".\n$snapLen is the maximum amount of bytes to capture per packet.\n$timeout specifies the read timeout in milliseconds.\n\nThen, loop!\nwhile(true) {\n    // Get a packet\n    $packet = $simplePcap-\u003eget(); // Returns a 'Packet' Object.\n\n    // Get the data\n    $data = $packet-\u003egetData(); // Returns a string\n\n    // Get the packet information\n    $capturedLen = $packet-\u003egetCapturedLen();\n    $realLen = $packet-\u003egetRealLen();\n    $timeSeconds = $packet-\u003egetSecondsOffset();\n    $timeMicroSeconds = $packet-\u003egetMicroSecondsOffset();\n}\n\nThat's it. Happy sniffing!\n\nInjecting Packets\n-----------------\n$totalBytesSent = $simplePcap-\u003esend($rawPacketData);\n\nHint: If you want to try it quickly, you can sniff packets and save them to a file. Do\na file_get_contents() on it when calling send(), to reinject it :) If not, you will have\nto forge your packet.\n\nNote: Since the SimplePcap constructor calls pcap_open_live(), even if you're opening the\ninterface just to inject packets (.. wont comment anything on that.. ) you will still need\nto pass all the arguments.\n\nCompiling\n=========\nEdit the GNUmakefile. You will need to specify the SWIG binary location and\nthe php include directory (for the .h files). Then, just:\n$ gmake\n\nThe \"build\" directory will be generated, with the SimplePcap.so file. Include it in your\nphp.ini file like:\nextension=SimplePcap.so\n\nSee the example directory, that ships a sample php.ini file that you can use with the -c flag for php:\n\n$ cd example\n$ php -c php.ini list.php\nany =\u003e Pseudo-device that captures on all interfaces\neth0 =\u003e\nlo =\u003e\n\n$ php -c php.ini sniff.php eth0 \"port 80\" 4096 0\n...\n00080   2e 31 0d 0a 48 6f 73 74    3a 20 77 77 77 2e 67 6f    .1..Host   : www.go\n00096   6f 67 6c 65 2e 63 6f 6d    0d 0a 55 73 65 72 2d 41    ogle.com   ..User-A\n00112   67 65 6e 74 3a 20 4c 69    6e 6b 73 20 28 32 2e 32    gent: Li   nks (2.2\n00128   3b 20 4c 69 6e 75 78 20    32 2e 36 2e 32 39 2d 67    ; Linux    2.6.29-g\n00144   65 6e 74 6f 6f 2d 72 31    20 78 38 36 5f 36 34 3b    entoo-r1    x86_64;\n00160   20 31 32 36 78 34 34 29    0d 0a 41 63 63 65 70 74     126x44)   ..Accept\n00176   3a 20 2a 2f 2a 0d 0a 41    63 63 65 70 74 2d 45 6e    : */*..A   ccept-En\n00192   63 6f 64 69 6e 67 3a 20    67 7a 69 70 2c 20 64 65    coding:    gzip, de\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarcelog%2Fsimplepcap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarcelog%2Fsimplepcap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarcelog%2Fsimplepcap/lists"}