Fast algorithm to compare an IP address against a list of IP sections?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Fast algorithm to compare an IP address against a list of IP sections?
# 8  
Old 11-27-2010
I don't know if it's efficient enough:

Code:
perl -MSocket -lane'  
    push @r, [ 
      unpack ("N", inet_aton $F[0]), 
      unpack ("N", inet_aton $F[1]), 
      $F[2] 
      ] and next if @ARGV;

    $n = unpack "N", inet_aton $F[0];
    $c = $_;

    do {
      print "$c\t$_->[2]" and last 
        if $_->[0] <= $n && $n <= $_->[1]
        }  for @r
        ' file1 file2

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

IP address list padding with 0

Hi All, I'm hoping one of you helpful lot could come up with a way I can do the below. I've been trying to think how is best but have struggled to come up with a way. I have a list of IP addresses in the below format 1.1.1.1 102.1.2.3 102.102.1.10 102.102.102.1 I need to compare... (4 Replies)
Discussion started by: mutley2202
4 Replies

2. Shell Programming and Scripting

List the IP address of list of servers

Hi I have a file containing server names and i can ssh to all these servers without password. Could any body suggest me how to list out IP address of all the servers? Now i am manually doing this, like ssh to each server and run "ifcong -a" command and copy the ipaddress to a excel sheet.... (5 Replies)
Discussion started by: kumar85shiv
5 Replies

3. Shell Programming and Scripting

Compare IP Address from nslookup and file

Hi, I am trying to compare IP address of a server using nslookup with IP address in a file (serverlist). And if there is a difference in IP, it should send an email. But there is some error in the pgm... Please help... #!/usr/bin/ksh for server in `cat serverlist` do old_ip=`cat... (12 Replies)
Discussion started by: vkk
12 Replies

4. UNIX for Dummies Questions & Answers

compare / difference between sub-sections of files

Hi there, I'm sure this question has been asked many times but I can't find any posts with information. How can I check the differences between say lines 20 - 200 in file1 and lines 420 - 600 in file2? Thanks in advance for any help! js (2 Replies)
Discussion started by: js8765
2 Replies

5. Shell Programming and Scripting

ksh - how to list all ip address between 2 ip address

Trying to do a ksh script that needs to list all ip address between ip address a and b .. ie. Ip address A=192.168.1.200 Ip address B=192.168.2.15 So the subnet changes from 1 to 2 but I want to list all possible ip addresses between the 2.. Which would be: 192.168.1.200... (4 Replies)
Discussion started by: frustrated1
4 Replies

6. UNIX for Advanced & Expert Users

fast way to retreive a list of lines

hi there, i have to read lines from the file, where the line is just above the pattern am looking for typically this looks like this <time-stamp>|----- <pattern am searching >...... <time-stamp>|..... <some garbage > .... the log file is big wc -l ~/log/ompe.log.20081203... (8 Replies)
Discussion started by: kiranreddy1215
8 Replies

7. Shell Programming and Scripting

script to compare two files of mac address

Hi I need to write a bash shell script. I have two separate text files. One file contains a list of MAC addresses taken from a network scan, the other contains a list of MAC addresses for our currently-managed devices. How can I compare these two files, and output a list of addresses that have... (6 Replies)
Discussion started by: borderblaster
6 Replies

8. UNIX for Dummies Questions & Answers

send email from address list and subject list

Hello, Here is my problem. there are two files. first.txt <<< contains email address ====== abc@mail.com abd@mail.com abe@mail.com second.txt <<< contains webpage links ======== http//www.test.com/abc/index.html http://www.test.com/abd/index.html http://www.test.com/abe/index.html... (2 Replies)
Discussion started by: paulds
2 Replies

9. UNIX for Dummies Questions & Answers

Slow from static IP ... fast from NAT address

Has anyone had an issue where: If I telnet into a unix machine on my network, from within my natted address, there is no speed issue. When I telnet to the same machine using the static address, it is very very slow. This SCO 5.06. There is no nameserver running. Please help. I have... (3 Replies)
Discussion started by: gseyforth
3 Replies

10. Shell Programming and Scripting

fast searching algorithm

hello, i need a searching algorithm in unix. since my input file is very bulky, so need a real fast searching algorithm, to match words. i am already using grep. (3 Replies)
Discussion started by: rochitsharma
3 Replies
Login or Register to Ask a Question
FS_GETSERVERPREFS(1)					       AFS Command Reference					      FS_GETSERVERPREFS(1)

NAME
fs_getserverprefs - Displays preference ranks for file servers or VL servers SYNOPSIS
fs getserverprefs [-file <output to named file>] [-numeric] [-vlservers] [-help] fs gets [-f <output to named file>] [-n] [-v] [-h] fs gp [-f <output to named file>] [-n] [-v] [-h] DESCRIPTION
The fs getserverprefs command displays preference ranks for file server machine interfaces (file server machines run the fs process) or, if the -vlserver flag is provided, for Volume Location (VL) Server machines (which run the vlserver process). For file server machines, the Cache Manager tracks up to 15 interfaces per machine and assigns a separate rank to each interface. The ranks indicate the order in which the local Cache Manager attempts to contact the interfaces of machines that are housing a volume when it needs to fetch data from the volume. For VL Server machines, the ranks indicate the order in which the Cache Manager attempts to contact a cell's VL Servers when requesting VLDB information. For both types of rank, lower integer values are more preferred. The Cache Manager stores ranks in kernel memory. Once set, a rank persists until the machine reboots, or until the fs setserverprefs command is used to change it. fs_setserverprefs(1) explains how the Cache Manager sets default ranks, and how to use that command to change the default values. Default VL Server ranks range from 10,000 to 10,126. The Cache Manager assigns ranks to every machine listed in its copy of the /etc/openafs/CellServDB file or found via DNS AFSDB or SRV records for the cell when it initializes. When the Cache Manager needs to fetch VLDB information from a cell, it compares the ranks for the VL Server machines belonging to that cell, and attempts to contact the VL Server with the lowest integer rank. If the Cache Manager cannot reach the VL Server (because of server process, machine or network outage), it tries to contact the VL Server with the next lowest integer rank, and so on. If all of a cell's VL Server machines are unavailable, the Cache Manager cannot fetch data from the cell. Default file server ranks range from 5,000 to 40,000, excluding the range used for VL Servers (10,000 to 10,126); the maximum possible rank is 65,534. When the Cache Manager needs to fetch data from a volume, it compares the ranks for the interfaces of machines that house the volume, and attempts to contact the interface that has the lowest integer rank. If it cannot reach the fileserver process via that interface (because of server process, machine or network outage), it tries to contact the interface with the next lowest integer rank, and so on. If it cannot reach any of the interfaces for machines that house the volume, it cannot fetch data from the volume. For both file server machines and VL Server machines, it is possible for a machine or interface in a foreign cell to have the same rank as a machine or interface in the local cell. This does not present a problem, because the Cache Manager only ever compares ranks for machines belonging to one cell at a time. OPTIONS
-file <output file> Specifies the full pathname of a file to which to write the preference ranks. If the specified file already exists, the command overwrites its contents. If the pathname is invalid, the command fails. If this argument is not provided, the preference ranks appear on the standard output stream. -numeric Displays the IP addresses of file server machine interfaces or VL Server machines, rather than their hostnames. If this argument is not provided, the fs command interpreter has the IP addresses translated to hostnames such as "fs1.abc.com". -vlservers Displays preference ranks for VL Server machines rather than file server machine interfaces. -help Prints the online help for this command. All other valid options are ignored. OUTPUT
The output consists of a separate line for each file server machine interface or VL Server machine, pairing the machine's hostname or IP address with its rank. The Cache Manager stores IP addresses in its kernel list of ranks, but the command by default identifies interfaces by hostname, by calling a translation routine that refers to either the cell's name service (such as the Domain Name Server) or the local host table. If an IP address appears in the output, it is because the translation attempt failed. To bypass the translation step and display IP addresses rather than hostnames, include the -numeric flag. This can significantly speed the production of output. By default, the command writes to the standard output stream. Use the -file argument to write the output to a file instead. EXAMPLES
The following example displays the local Cache Manager's preference ranks for file server machines. The local machine belongs to the AFS cell named abc.com, and in this example the ranks of file server machines in its local cell are lower than the ranks of file server machines from the foreign cell, "def.com". It is not possible to translate the IP addresses of two machines on the 138.255 network. % fs getserverprefs fs2.abc.com 20007 fs3.abc.com 30002 fs1.abc.com 20011 fs4.abc.com 30010 server1.def.com 40002 138.255.33.34 40000 server6.def.com 40012 138.255.33.37 40005 The following example shows hows the output displays IP addresses when the -numeric flag is included, and illustrates how network proximity determines default ranks (as described on the fs setserverprefs reference page). The local machine has IP address 192.12.107.210, and the two file server machines on its subnetwork have ranks of 20,007 and 20,011. The two file server machines on a different subnetwork of the local machine's network have higher ranks, 30,002 and 30,010, whereas the ranks of the remaining machines range from 40,000 to 40,012 because they are in a completely different network. % fs getserverprefs -numeric 192.12.107.214 20007 192.12.105.99 30002 192.12.107.212 20011 192.12.105.100 30010 138.255.33.41 40002 138.255.33.34 40000 138.255.33.36 40012 138.255.33.37 40005 The example shows how the -vlservers flag displays preference ranks for VL Server machines: % fs getserverprefs -vlservers fs2.abc.com 10052 fs3.abc.com 10113 fs1.abc.com 10005 PRIVILEGE REQUIRED
None SEE ALSO
fs_setserverprefs(1) COPYRIGHT
IBM Corporation 2000. <http://www.ibm.com/> All Rights Reserved. This documentation is covered by the IBM Public License Version 1.0. It was converted from HTML to POD by software written by Chas Williams and Russ Allbery, based on work by Alf Wachsmann and Elizabeth Cassell. OpenAFS 2012-03-26 FS_GETSERVERPREFS(1)