Net::Libdnet

Binding for Dug Song's libdnet
Download

Net::Libdnet Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Patrice Auffret
  • Publisher web site:
  • http://search.cpan.org/~gomor/

Net::Libdnet Tags


Net::Libdnet Description

Binding for Dug Song's libdnet Net::Libdnet is a Perl module that provides a simplified, portable interface to several low-level networking routines, including network address manipulation, kernel arp cache and route table lookup and manipulation, network firewalling, network interface lookup and manipulation, network traffic interception via tunnel interfaces, and raw IP packet and Ethernet frame transmission. It is intended to complement the functionality provided by libpcap.All the original and obsolete functions return undef and print a warning message to the standard error when a problem occurs. The obsolete functions are: addr_cmp, addr_bcast, addr_net, arp_add, arp_delete, arp_get, intf_get, intf_get_src, intf_get_dst, route_add, route_delete, route_get.These osbsolete functions will continue to work, to keep backward compatibility, but should not be used anymore. The new APIs should be prefered. There are two new APIs, one is the low-level one, matching libdnet functions, and the other one is a high-level API, matching a more Perl object oriented programming. This latest one is highly prefered.Net::Libdnet module implements the low-level API. The high-level API is accessible by using the following modules: Net::Libdnet::Intf, Net::Libdnet::Route, Net::Libdnet::Fw, Net::Libdnet::Arp, Net::Libdnet::Eth, Net::Libdnet::Ip and Net::Libdnet::Tun.SYNOPSIS # # This will just import every functions and constants # use Net::Libdnet; # # Network interface manipulation # # !!! ADVICE: you should use Net::Libdnet::Intf instead # use Net::Libdnet qw(:intf); my $intf = dnet_intf_open(); my $eth = dnet_intf_get($intf, { intf_name => 'eth0' }); print "IP: ".$eth->{intf_addr}."\n"; print "MAC: ".$eth->{intf_link_addr}."\n"; my $dst = dnet_intf_get_dst($intf, '192.168.0.10'); print "Name: ".$dst->{intf_name}."\n"; print "IP: ".$dst->{intf_addr}."\n"; print "MAC: ".$dst->{intf_link_addr}."\n"; my $src = dnet_intf_get_src($intf, '192.168.0.1'); print "Name: ".$src->{intf_name}."\n"; print "IP: ".$src->{intf_addr}."\n"; print "MAC: ".$src->{intf_link_addr}."\n"; dnet_intf_close($intf); # # Arp cache manipulation # # !!! ADVICE: you should use Net::Libdnet::Arp instead # use Net::Libdnet qw(:arp); my $arp = dnet_arp_open(); my $entry = dnet_arp_get($arp, {arp_pa => '10.0.0.1'}); print "MAC: ".$entry->{arp_ha}."\n"; dnet_arp_add ($arp, {arp_ha => '00:11:22:33:44:55', arp_pa => '10.0.0.10'}); dnet_arp_delete($arp, {arp_ha => '00:11:22:33:44:55', arp_pa => '10.0.0.10'}); dnet_arp_close($arp); # # Route table manipulation # # !!! ADVICE: you should use Net::Libdnet::Route instead # use Net::Libdnet qw(:route); my $route = dnet_route_open(); dnet_route_add ($route, {route_gw => '10.0.0.1', route_dst => '192.168.0.1'}); dnet_route_delete($route, {route_gw => '10.0.0.1', route_dst => '192.168.0.1'}); my $get = dnet_route_get($route, {route_dst => '192.168.0.10'}); print "GW: ".$get->{route_gw}."\n"; dnet_route_close($route); # # Firewall rules manipulation # # !!! ADVICE: you should use Net::Libdnet::Fw instead # use Net::Libdnet qw(:fw :consts); my $fw = dnet_fw_open(); # This is quite complex. This rule blocks TCP as input to 10.0.0.1 # You should really use Net::Libdnet::Fw instead. dnet_fw_add ($fw, {fw_op => FW_DIR_IN, fw_proto => 6, fw_dst => '10.0.0.1'}); dnet_fw_delete($fw, {fw_op => FW_DIR_IN, fw_proto => 6, fw_dst => '10.0.0.1'}); dnet_fw_close($fw); # # Send at IP level # # !!! ADVICE: you should use Net::Libdnet::Ip instead # use Net::Libdnet qw(:ip); my $ip = dnet_ip_open(); my $raw = "\x47\x47\x47\x47"; dnet_ip_send($ip, $raw, length($raw)); dnet_ip_close($ip); # # Send at Ethernet level # # !!! ADVICE: you should use Net::Libdnet::Eth instead # use Net::Libdnet qw(:eth); my $eth = dnet_eth_open('eth0'); dnet_eth_send($eth, $raw, length($raw)); dnet_eth_close($eth); # # Traffic interception # # !!! ADVICE: you should use Net::Libdnet::Tun instead # use Net::Libdnet qw(:tun); my $tun = dnet_tun_open('10.0.0.10', '192.168.0.10', 1500); my $buf = dnet_tun_recv($tun, 1500); # Do stuff with $buf dnet_tun_send($tun, $buf, length($buf)); dnet_tun_close($tun); # # hash refs in dnet format # my $intf = { intf_alias_num => 1, intf_mtu => 1500, intf_len => 112, intf_type => 6, intf_name => 'eth0', intf_dst_addr => undef, intf_link_addr => '00:11:22:33:44:55', intf_flags => 49, intf_addr => '10.100.0.10/24', intf_alias_addrs => }; my $arp = { arp_pa => '10.100.0.1', arp_ha => '11:22:33:44:55:66' }; my $route = { route_gw => '10.100.0.1', route_dst => '0.0.0.0/0' }; my $fw = { fw_dir => 2, fw_sport => , fw_dport => , fw_src => '0.0.0.0/0', fw_dst => '0.0.0.0/0', fw_proto => 6, fw_device => 'eth0', fw_op => 2 }; Requirements: · Perl


Net::Libdnet Related Software