jruby-pcap 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0e368b6eb13ca3c5d7537ff75efb0ecd5e282774
4
+ data.tar.gz: 3075fc6c60e15bcf9d98141d5ea8b7b9723f839a
5
+ SHA512:
6
+ metadata.gz: 938f9fa6be0c37ecca1c4a59ea1fab2446c38ec0f76ef25da2016b7bc45dd9e5d22a4df3380b92d3f875485e9d94033f78b1df3e36d88d262610d78720f2f268
7
+ data.tar.gz: a2977eaf2411839d1ea64c1c26e12d27dc4ba498a8e3f1a4850fa3a038177efce36103a16f2533aef20e3cb6cd9d9d110bb10735cda70eeee02a8295f00c4259
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in jruby-pcap.gemspec
4
+ gemspec
5
+
6
+ gem 'rspec', '~> 3.2.0'
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Pere Urbon-Bayes
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,39 @@
1
+ # Jruby::Pcap
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/jruby/pcap`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'jruby-pcap'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install jruby-pcap
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ 1. Fork it ( https://github.com/[my-github-username]/jruby-pcap/fork )
36
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
37
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
38
+ 4. Push to the branch (`git push origin my-new-feature`)
39
+ 5. Create a new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "jruby/pcap"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'jruby-pcap/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "jruby-pcap"
8
+ spec.version = Jruby::Pcap::VERSION
9
+ spec.authors = ["Pere Urbon-Bayes"]
10
+ spec.email = ["pere.urbon@elastic.co"]
11
+
12
+ spec.summary = "A basic jruby gem wrapper on top of pcap4j"
13
+ spec.description = "This gem leverages the java lib pcap4j to enable jruby developers to analyse network packets"
14
+ spec.homepage = "http://github.com/purbon/jruby-pcap"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.9"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ end
Binary file
@@ -0,0 +1,22 @@
1
+ require "jruby-pcap/packet"
2
+ java_import java.sql.Timestamp
3
+
4
+ module Jruby::Pcap
5
+ class FileHandle
6
+
7
+ include Enumerable
8
+ attr_reader :handle
9
+
10
+ def initialize(handle)
11
+ @handle = handle
12
+ end
13
+
14
+ def each
15
+ next_packet = @handle.next_packet_ex
16
+ if next_packet
17
+ yield Jruby::Pcap::Packet.new(next_packet, @handle)
18
+ end
19
+ end
20
+
21
+ end
22
+ end
@@ -0,0 +1,21 @@
1
+ module Jruby::Pcap
2
+ class Frame
3
+
4
+ def initialize(handle, frame)
5
+ @handle = handle
6
+ @frame = frame
7
+ end
8
+
9
+ def src_addr
10
+ @frame.header.src_addr.to_s.gsub("/","")
11
+ end
12
+
13
+ def src_host
14
+ @frame.header.src_addr.host_name
15
+ end
16
+
17
+ def is_a?(clazz)
18
+
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,28 @@
1
+ require "jruby-pcap/packet"
2
+ java_import java.sql.Timestamp
3
+
4
+ module Jruby::Pcap
5
+ class LiveHandle
6
+
7
+ include Enumerable
8
+
9
+ def initialize(interface)
10
+ @interface = interface
11
+ end
12
+
13
+ def each
14
+ handle = @interface.open_live(1024, PcapNetworkInterface::PromiscuousMode::PROMISCUOUS, 0)
15
+ while true do
16
+ puts "start"
17
+ next_packet = handle.next_packet_ex
18
+ puts "next_packet"
19
+ if next_packet
20
+ yield Packet.new(next_packet, handle)
21
+ else
22
+ break
23
+ end
24
+ end
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,23 @@
1
+ require "jruby-pcap/frame"
2
+
3
+ module Jruby::Pcap
4
+ class Packet
5
+
6
+ def initialize(packet, handle)
7
+ @packet = packet
8
+ @handle = handle
9
+ end
10
+
11
+ def timestamp
12
+ @handle.get_timestamp_ints * 1000
13
+ end
14
+
15
+ def ipv4
16
+ Frame.new(@handle, @packet.get(IpV4Packet))
17
+ end
18
+
19
+ def to_s
20
+ @packet.to_s
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,5 @@
1
+ module Jruby
2
+ module Pcap
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,37 @@
1
+ require "java"
2
+ require "jruby-pcap/version"
3
+ require "jruby-pcap/file_handle"
4
+ require "jruby-pcap/live_handle"
5
+
6
+ require "jars/pcap4j-core-1.4.0.jar"
7
+ require "jars/pcap4j-packetfactory-static-1.4.0.jar"
8
+ require "jars/jna-4.1.0.jar"
9
+ require "jars/slf4j-api-1.6.4.jar"
10
+
11
+ java_import org.pcap4j.core.PcapHandle
12
+ java_import org.pcap4j.core.PcapNativeException
13
+ java_import org.pcap4j.core.Pcaps
14
+ java_import org.pcap4j.packet.IpV4Packet
15
+ java_import org.pcap4j.packet.Packet
16
+ java_import org.pcap4j.packet.TcpPacket
17
+ java_import org.pcap4j.packet.UdpPacket
18
+ java_import org.pcap4j.util.NifSelector
19
+ java_import org.pcap4j.core.PcapNetworkInterface
20
+
21
+ module Jruby
22
+ module Pcap
23
+
24
+ def self.open(file)
25
+ FileHandle.new(Pcaps.openOffline(file))
26
+ end
27
+
28
+ def self.live(name)
29
+ interface = Pcaps.get_dev_by_name(name)
30
+ LiveHandle.new(interface)
31
+ end
32
+
33
+ def self.devs
34
+ Pcaps.findAllDevs
35
+ end
36
+ end
37
+ end
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jruby-pcap
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Pere Urbon-Bayes
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-05-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ version_requirements: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.9'
20
+ requirement: !ruby/object:Gem::Requirement
21
+ requirements:
22
+ - - ~>
23
+ - !ruby/object:Gem::Version
24
+ version: '1.9'
25
+ prerelease: false
26
+ type: :development
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ requirement: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ~>
37
+ - !ruby/object:Gem::Version
38
+ version: '10.0'
39
+ prerelease: false
40
+ type: :development
41
+ description: This gem leverages the java lib pcap4j to enable jruby developers to analyse network packets
42
+ email:
43
+ - pere.urbon@elastic.co
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - .rspec
50
+ - CODE_OF_CONDUCT.md
51
+ - Gemfile
52
+ - LICENSE.txt
53
+ - README.md
54
+ - Rakefile
55
+ - bin/console
56
+ - bin/setup
57
+ - jruby-pcap.gemspec
58
+ - lib/jars/jna-4.1.0.jar
59
+ - lib/jars/pcap4j-core-1.4.0.jar
60
+ - lib/jars/pcap4j-packetfactory-static-1.4.0.jar
61
+ - lib/jars/slf4j-api-1.6.4.jar
62
+ - lib/jruby-pcap/file_handle.rb
63
+ - lib/jruby-pcap/frame.rb
64
+ - lib/jruby-pcap/live_handle.rb
65
+ - lib/jruby-pcap/packet.rb
66
+ - lib/jruby-pcap/version.rb
67
+ - lib/pcap.rb
68
+ homepage: http://github.com/purbon/jruby-pcap
69
+ licenses:
70
+ - MIT
71
+ metadata: {}
72
+ post_install_message:
73
+ rdoc_options: []
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ requirements: []
87
+ rubyforge_project:
88
+ rubygems_version: 2.4.5
89
+ signing_key:
90
+ specification_version: 4
91
+ summary: A basic jruby gem wrapper on top of pcap4j
92
+ test_files: []