File: arp2ethers

package info (click to toggle)
arpwatch 2.1a4-3
  • links: PTS
  • area: main
  • in suites: potato
  • size: 572 kB
  • ctags: 233
  • sloc: ansic: 2,467; sh: 1,723; makefile: 140; awk: 61
file content (85 lines) | stat: -rwxr-xr-x 1,665 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/sh
# @(#) $Header: arp2ethers,v 1.2 94/03/29 02:44:44 leres Exp $ (LBL)
#
# Convert arp.dat to ethers format
#
#	- sort on timestamp, newest first
#	- discard entries without simple hostnames
#	- discard all but first occurance of each ethernet address
#	- discard entires with raw ip addresses for simple names
#	- remove ip address and timestamp fields
#	- append "-ip" to hosts with decnet address too
#	- append "-old", "-old1", etc. as necessary
#	- sort
#
# 1999-04-12	KELEMEN Peter <fuji@debian.org>
#	Use sh(1) instead of csh(1).
#
# 2000-03-21	Erik Warmelink <erik@selwerd.nl>
#	Use next instead of continue in included p.awk.

sort +2rn arp.dat | \
    awk 'NF == 4 { print }' | \
# 1999-04-12	KELEMEN Peter <fuji@debian.org>
#    awk -f p.awk | \
    awk '
# Only print the first ethernet address seen

{
	e = $1
	if (seen[e])
		next
	seen[e] = 1
	print $0
}
    ' | \
    egrep -v '\.[0-9][0-9]*$' | \
    sed -e 's/	.*	/	/' | \
# 1999-04-12	KELEMEN Peter <fuji@debian.org>
#    awk -f d.awk | \
    awk '
# DECnet hacking

BEGIN {
	n = 0
	sdecnet = "aa:0:4:"
	ldecnet = length(sdecnet)
}

{
	++n
	e[n] = $1
	h[n] = $2
	if (sdecnet == substr($1, 1, ldecnet))
		decnet[$2] = 1
}

END {
	for (i = 1; i <= n; ++i) {
		if (decnet[h[i]] && sdecnet != substr(e[i], 1, ldecnet))
			h[i] = h[i] "-ip"
		print e[i] "\t" h[i]
	}
}
    ' | \
# 1999-04-12	KELEMEN Peter <fuji@debian.org>
#    awk -f e.awk | \
    awk '
# Add -old suffix to ethers file, as required. Assumed sorted input

{
	if (!seen[$2]) {
		seen[$2] = 1
		print
		next
	}
	h = $2 "-old"
	s = h
	for (n = 1; seen[h]; ++n)
		h = s n
	seen[h] = 1
	print $1 "\t" h
	next
}
    ' | \
    sort