s-traceroute

来自「ftam等标准协议服务器和客户端的源代码。」· 代码 · 共 106 行

TXT
106
字号
: run this script through /bin/shagent= community= dest= flags=for A in $*do    case $A in	-*)	echo "$A: unknown flag" 1>&2		exit 1 ;;	*)	if [ "x$dest" = "x" ]; then		    dest="-v DEST=$A"		elif [ "x$community" = "x" ]; then		    community="-v COMMUNITY=$A"		elif [ "x$agent" = "x" ]; then		    agent="-v AGENT=$A"		else		    echo "usage: s-traceroute [switches] destination [community [agent]]" 1>&2		    exit 1		fi ;;    esacdoneif [ "x$dest" = "x" ]; then    echo "no destination specified" 1>&2    exit 1fiunset MIBDEFSexec gawk $flags $agent $community $dest 'BEGIN	{	    printf "from %s to %s:\n", AGENT, DEST;	    tried[AGENT] = 1;	    INVALID = 2; DIRECT = 3;	    split (DEST, dest, ".");	    if (dest[1] < 128)		net = dest[1];	    else		if (dest[1] < 192)		    net = dest[1] "." dest[2];		else		    net = dest[1] "." dest[2] "." dest[3];	    while (DEST != AGENT) {		dr = 0;		gotit = 0;		for (i in ipRouteMask, net) {		    if ((type = ipRouteType) == INVALID)		        continue;		    split(ipRouteMask, mask, ".");		    mask = bit_and(dest[1],mask[1]) "." \			   bit_and(dest[2],mask[2]) "." \			   bit_and(dest[3],mask[3]) "." \			   bit_and(dest[4],mask[4]);		    if (mask == ipRouteDest) {			hop = ipRouteNextHop;			gotit = 1;			break;		    }		}		if (!gotit) {		    if ((hop = ipRouteNextHop[addr = DEST]) \			    && (type = ipRouteType[addr]) == INVALID)			hop = 0;		    if (!hop \			    && (hop = ipRouteNextHop[addr = net]) \			    && (type = ipRouteType[addr]) == INVALID)			hop = 0;		    if (!hop && (hop = ipRouteNextHop[addr = "0.0.0.0"])) {			if ((type = ipRouteType[addr]) == INVALID)			    hop = 0;			else			    dr = 1;		    }		}		if (hop) {		    printf "    via %-15s metric %2d%s\n",			    hop, ipRouteMetric1[addr],			    dr ? " (default route)" : "";		}		else {		    printf "\nno path to %s from %s\n%s\n", 			    DEST, AGENT, DIAGNOSTIC;		    exit(1);		}		if (type == DIRECT) {		    printf "\tdirect route.\n";		    exit(0);		}		if (hop in tried)		    printf "\nrouting loop!\n";		else		    tried[hop] = 1;		AGENT = hop;	    }	    printf "\tdone.\n";	}'

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?