Sponsored Content
Top Forums Shell Programming and Scripting Search IP Address in list of ranges -- not working great Post 302601061 by tsunami4u on Wednesday 22nd of February 2012 09:06:36 PM
Old 02-22-2012
Search IP Address in list of ranges -- not working great

I have been struggling with a script to automate some security related activities. I have it pretty much working, all except the search. I have an input file formatted as such:
Code:
216.234.246.158    216.234.246.158    `[Spyware_Sites]`
        
24.249.221.22    24.249.221.200    `[Spyware_Sites]`
        
24.249.226.0    24.249.226.255    `[Spyware_Sites]`
        
24.23.0.0    24.30.255.255    `[Spyware_Sites]`
        
64.14.90.11    64.14.97.255    `[Spyware_Sites]`
        
64.128.107.0    64.128.107.255    `[Spyware_Sites]`
        
64.60.0.0    64.62.255.255    `[Spyware_Sites]`
        
64.62.133.6    64.62.133.6    `[Spyware_Sites]`

This represents ranges of IP addresses that have been defined in a security appliance. I need to search this file to determine if the input variable (An single IP Address) falls within any of these ranges. If so display the line.

I am a a novice at development, and naively though this would be fairly straight-forward. It wasn't. However, after many false starts, I was able to get some fairly accurate (fuzzy) results by iteratively searching the first octect for an exact match>file, then using agrep -B to find the best match from there. My code:

Code:
echo $1 >htmp1.tmp
cut -f 1 -d "." htmp1.tmp >htmp2.tmp
var1=$(cat htmp2.tmp)
grep -E ''"^$var1"'\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' hgworking.txt >htmp3.tmp
agrep -B -y $1 htmp3.tmp

This is not ideal, but works for now. I am new to programming -- surely there are folks out there that help me produce more exact results. Thanks in advance!

- Kevin
 

8 More Discussions You Might Find Interesting

1. 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

2. Shell Programming and Scripting

Search values between ranges in File1 within File2

Hi people, I have 2 files, one with a list of non consecutive ranges (File1.txt), where each range begins with the value in column 1 and finishes with the value in column 2 in the same line, as can be seen above. 215312581156279 215312581166279 215312582342558 215312582357758... (4 Replies)
Discussion started by: cgkmal
4 Replies

3. 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

4. Shell Programming and Scripting

Help with gawk script that aggregates ip address ranges

Howdy folks, perhaps someone can help me with this problem. My knowledge of awk is not the best... but I've managed to a certain degree and now I'm stuck. These are the steps and the format outputs, problem is written in red text after the STEP 2: STEP 1 Unformated text file (100+... (3 Replies)
Discussion started by: gustisok
3 Replies

5. Shell Programming and Scripting

search on weblogic logs with date time ranges 2

Hi All, The developers want me to search and capture the weblogic log, you know this big logs of htmls. They want to me to have ranges on the date and time. Like from "2010-01-20 14:04:46,186" to "2010-01-20 15:00:12,490" I can only do this, cat /usr/local/bea/logs_prod1/debug.log |... (1 Reply)
Discussion started by: itik
1 Replies

6. Linux

search on weblogic logs with date time ranges

Hi All, The developers want me to search and capture the weblogic log, you know this big logs of htmls. They want to me to have ranges on the date and time. Like from "2010-01-20 14:04:46,186" to "2010-01-20 15:00:12,490" I can only do this, cat /usr/local/bea/logs_prod1/debug.log... (1 Reply)
Discussion started by: itik
1 Replies

7. Shell Programming and Scripting

awk working inside specific pattern ranges

Hi, I have a text file, which I am trying to parse. File contents: BEG Id Job1 Id Stage1 1 EN Id Job2 Id Stage2 BEG Id2 Job3 Id Stage4 2 EN I have to process the data in this between every BEG and EN. so I am trying to restrict the range and inside every... (1 Reply)
Discussion started by: Kulasekar
1 Replies

8. UNIX for Beginners Questions & Answers

Search files between date ranges - Ctime usage

Hello, I am a noob and need some help. I am trying to find files created between a date range. For Example: These are files in directory. -rw-r--r-- 1 user staff 6 May 8 09:43 file1.txt -rw-r--r-- 1 user staff 6 May 8 09:43 file2.txt -rw-r--r-- 1 user... (8 Replies)
Discussion started by: r@v!7*7@
8 Replies
chdir(2)							System Calls Manual							  chdir(2)

NAME
chdir, fchdir - change working directory SYNOPSIS
DESCRIPTION
and cause a directory pointed to by path or fildes to become the current working directory, the starting point for path searches of path names not beginning with path points to the path name of a directory. fildes is an open file descriptor of a directory. For a directory to become the current working directory, a process must have execute (search) access to the directory. RETURN VALUE
Upon successful completion, a value of 0 is returned. Otherwise, a value of -1 is returned and is set to indicate the error. ERRORS
fails and the current working directory remains unchanged if one or more of the following are true: A component of the path name is not a directory. The named directory does not exist. Search permission is denied for any component of the path name. path points outside the allocated address space of the process. The reliable detection of this error is implemen- tation dependent. path is null. The length of the specified path name exceeds bytes, or the length of a component of the path name exceeds bytes while is in effect. Too many symbolic links were encountered in translating the path name. fails and the current working directory remains unchanged if one or more of the following are true: Search permission is denied for fildes. fildes is not an open file descriptor. The open file descriptor fildes does not refer to a directory. AUTHOR
and were developed by AT&T Bell Laboratories and HP. SEE ALSO
cd(1), chroot(2), privileges(5). STANDARDS CONFORMANCE
chdir(2)
All times are GMT -4. The time now is 05:16 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy