mirror of
https://github.com/vincentmli/bpfire.git
synced 2026-04-28 11:43:25 +02:00
captive: Get MAC address of a device without calling arp
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
This commit is contained in:
@@ -374,6 +374,26 @@ sub wifi_get_signal_level($) {
|
|||||||
|
|
||||||
return $signal_level;
|
return $signal_level;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub get_hardware_address($) {
|
||||||
|
my $ip_address = shift;
|
||||||
|
my $ret;
|
||||||
|
|
||||||
|
open(FILE, "/proc/net/arp") or die("Could not read ARP table");
|
||||||
|
|
||||||
|
while (<FILE>) {
|
||||||
|
my ($ip_addr, $hwtype, $flags, $hwaddr, $mask, $device) = split(/\s+/, $_);
|
||||||
|
if ($ip_addr eq $ip_address) {
|
||||||
|
$ret = $hwaddr;
|
||||||
|
last;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
close(FILE);
|
||||||
|
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
||||||
# Remove the next line to enable the testsuite
|
# Remove the next line to enable the testsuite
|
||||||
|
|||||||
@@ -58,9 +58,8 @@ if ($cgiparams{'ACTION'} eq "SUBMIT") {
|
|||||||
#Get Clients IP-Address
|
#Get Clients IP-Address
|
||||||
my $ip_address = $ENV{X_FORWARDED_FOR} || $ENV{REMOTE_ADDR} ||"";
|
my $ip_address = $ENV{X_FORWARDED_FOR} || $ENV{REMOTE_ADDR} ||"";
|
||||||
|
|
||||||
#Ask arp to give the corresponding MAC-Address
|
# Retrieve the MAC address from the ARP table
|
||||||
my $mac_address = qx(arp -a|grep $ip_address|cut -d ' ' -f 4);
|
my $mac_address = &Network::get_hardware_address($ip_address);
|
||||||
$mac_address =~ s/\n+\z//;
|
|
||||||
|
|
||||||
&General::readhasharray("$clients", \%clientshash);
|
&General::readhasharray("$clients", \%clientshash);
|
||||||
my $key = &General::findhasharraykey(\%clientshash);
|
my $key = &General::findhasharraykey(\%clientshash);
|
||||||
@@ -84,15 +83,13 @@ if ($cgiparams{'ACTION'} eq "SUBMIT") {
|
|||||||
|
|
||||||
if ($cgiparams{'ACTION'} eq "SUBMIT") {
|
if ($cgiparams{'ACTION'} eq "SUBMIT") {
|
||||||
my $ip_address;
|
my $ip_address;
|
||||||
my $mac_address;
|
|
||||||
my $granted=0;
|
my $granted=0;
|
||||||
#Convert voucherinput to uppercase
|
#Convert voucherinput to uppercase
|
||||||
$cgiparams{'VOUCHER'} = uc $cgiparams{'VOUCHER'};
|
$cgiparams{'VOUCHER'} = uc $cgiparams{'VOUCHER'};
|
||||||
#Get Clients IP-Address
|
#Get Clients IP-Address
|
||||||
$ip_address = $ENV{X_FORWARDED_FOR} || $ENV{REMOTE_ADDR} ||"";
|
$ip_address = $ENV{X_FORWARDED_FOR} || $ENV{REMOTE_ADDR} ||"";
|
||||||
#Ask arp to give the corresponding MAC-Address
|
#Ask arp to give the corresponding MAC-Address
|
||||||
$mac_address = qx(arp -a|grep $ip_address|cut -d ' ' -f 4);
|
my $mac_address = &Network::get_hardware_address($ip_address);
|
||||||
$mac_address =~ s/\n+\z//;
|
|
||||||
#Check if voucher is valid and write client to clients file, delete voucher from voucherout
|
#Check if voucher is valid and write client to clients file, delete voucher from voucherout
|
||||||
&General::readhasharray("$voucherout", \%voucherhash);
|
&General::readhasharray("$voucherout", \%voucherhash);
|
||||||
&General::readhasharray("$clients", \%clientshash);
|
&General::readhasharray("$clients", \%clientshash);
|
||||||
|
|||||||
Reference in New Issue
Block a user