2 个版本

0.1.1 2023年10月13日
0.1.0 2023年10月13日

#44 in #exists

Download history 15/week @ 2024-03-11 3/week @ 2024-03-25 69/week @ 2024-04-01 5/week @ 2024-04-08 4/week @ 2024-04-15 9/week @ 2024-04-22 1/week @ 2024-04-29 7/week @ 2024-05-06 5/week @ 2024-05-13 16/week @ 2024-05-20 6/week @ 2024-05-27 15/week @ 2024-06-03 13/week @ 2024-06-10 12/week @ 2024-06-17 11/week @ 2024-06-24

每月 52 次下载
用于 ipset

MIT 许可证

3KB

IPSet

Build Status GitHub issues GitHub license Releases

libipset的库包装器。
支持以下选项

  • sorted -> EnvOption::Sorted
  • exist -> EnvOption::Exist
  • quiet -> EnvOption::Quiet
  • resolve -> EnvOption::Resolve
  • name -> EnvOption::ListSetName
  • terse -> EnvOption::ListHeader

支持以下命令

  • add
  • del
  • test
  • create
  • list
  • destroy
  • flush
  • save
  • restore

支持以下类型

  • BitmapIp
  • BitmapIpMac
  • BitmapPort
  • HashIp
  • HashIpMac
  • HashIpMark
  • HashIpPort
  • HashIpPortIp
  • HashIpPortNet
  • HashMac
  • HashNet
  • HashNetIface
  • HashNetNet
  • HashNetPort
  • HashNetPortNet
  • ListSet,

示例

use std::net::IpAddr;

use ipset::{Error, HashIp, IPSet, Session};

fn main() -> Result<(), Error> {
  let mut session: Session<HashIp> = Session::<HashIp>::new("test".to_string());
  let ip: IpAddr = "192.168.3.1".parse().unwrap();
  session.create(|builder| builder.with_ipv6(false)?.build())?;

  let ret = session.add(ip, None)?;
  println!("add {}", ret);

  let exists = session.test(ip)?;
  println!("test {}", exists);

  let ips = session.list()?;
  for ip in ips {
      println!("list {}", ip);
  }

  let ret = session.save("test.ipset")?;
  println!("save {}", ret);

  let ret = session.del(ip)?;
  println!("del {}", ret);

  let ret = session.flush()?;
  println!("flush {}", ret);

  let ret = session.destroy()?;
  println!("destroy {}", ret);

  let set = IPSet::new();
  set.restore("test.ipset")?;

  Ok(())
}

依赖

~300–760KB
~18K SLoC