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:
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:
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!
An awk based solution along the same lines as the perl posted by balajesuri.
Searches for IP address passed in as $1 to the script. Optionally pass in the file to search, or redirect it in from stdin.
And before any flames are thrown about not needing the grep... No, it's not needed, but I assume it's faster to let awk munge a subset of the input rather than munging the whole input list.
Last edited by jim mcnamara; 02-23-2012 at 06:04 PM..
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)
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)
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)
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)
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)
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)
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)
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)