https://github.com/pepabo/mruby-ipfilter
https://github.com/pepabo/mruby-ipfilter
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/pepabo/mruby-ipfilter
- Owner: pepabo
- License: other
- Created: 2017-05-23T07:23:51.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-03-28T07:03:18.000Z (about 7 years ago)
- Last Synced: 2025-04-15T03:04:28.008Z (about 1 month ago)
- Language: Ruby
- Size: 11.7 KB
- Stars: 3
- Watchers: 19
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# mruby-ipfilter [](https://travis-ci.org/pepabo/mruby-ipfilter)
IPFilter class
## install by mrbgems
- add conf.gem line to `build_config.rb````ruby
MRuby::Build.new do |conf|# ... (snip) ...
conf.gem :github => 'tahira/mruby-ipfilter'
end
```
## example
```ruby
# CountryFromIP sample
cip = IPFilter::CountryFromIP.new('/tmp/GeoLite2-City.mmdb')
cip.permit = ['JP']target_ip = '8.8.8.8'
if cip.permit?(target_ip)
p "#{target_ip} is permit"
else
p "#{target_ip} is deny"
end# Path sample
path = IPFilter::Path.new()
path.deny = ['wp-login.php', 'xmlrpc.php']
target_path = '/blog/wp-login.php'
if path.deny?(target_path)
p "#{target_path} is deny"
else
p "#{target_path} is permit"
end# UserAgent sample
ua = IPFilter::UserAgent.new()
ua.permit = ['Googlebot', 'Twitterbot']
target_ua='Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)'
if ua.permit?(target_ua)
p "#{target_ua} is permit"
else
p "#{target_ua} is permit"
end
``````sh
❯ mruby/bin/mruby example/example.rb 1h 37m 24s 309ms
"8.8.8.8 is deny"
"/blog/wp-login.php is deny"
"Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html) is permit"
```## License
under the MIT License:
- see LICENSE file