980d87a8422707ece97495bcd0ac0af0e6f117c0
[people/pmueller/ipfire-2.x.git] / src / initscripts / helper / getdnsfromdhcpc.pl
1 #!/usr/bin/perl
2 ###############################################################################
3 # #
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2007 Michael Tremer & Christian Schmidt #
6 # #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
11 # #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
16 # #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
19 # #
20 ###############################################################################
21
22 use strict;
23 require '/var/ipfire/general-functions.pl';
24
25 my $count = $ARGV[0];
26 my ($dhcp, $dns, @alldns, %dhcpc);
27
28 if ($count eq "" || $count < 1) {
29 die "Bad DNS number given"; }
30
31 if (open(FILE, "${General::swroot}/red/iface")) {
32 my $iface = <FILE>;
33 close FILE;
34 chomp ($iface);
35 if (!&General::readhash("${General::swroot}/dhcpc/dhcpcd-$iface.info", \%dhcpc)) {
36 die "Could not open dhcpc info file";
37 }
38 } else {
39 die "Could not open interface file";
40 }
41
42
43 $dns = $dhcpc{'domain_name_servers'};
44
45 @alldns = split(',', $dns);
46
47 print "$alldns[$count - 1]\n";