Re: Parsing text for IP Addresses



On Feb 16, 5:13 pm, dan63...@xxxxxxxxx wrote:
On Feb 16, 11:36 am, Glenn Jackman <gle...@xxxxxx> wrote:

At 2007-02-16 11:36AM, "dan63...@xxxxxxxxx" wrote:

-re {(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})}> do_ping > exp_continue> }
The regex I suggested will not strictly match just IP addresses (i.e.
555.666.777.888 is an invalid IP but will be caught by that regex).
However it should do the trick. If you want to be more precise:

set re_255 {(?:25[0-5]|2[0-4]\d|1{0,1}\d{1,2})}
set re_ip "\\y$re_255\\.$re_255\\.$re_255\\.$re_255\\y"

Glenn Jackman
"You can only be young once. But you can always be immature." -- Dave Barry

Okay, that worked. THANK YOU!

FYI - I have ordered the O'Reilly books for TCL - they're not availble
at the local Boarders/Barnes and Noble. :(

Now, I don't want to be too greedy, but I realized after I posted this
that what I actually need is to look at the line below Target: and see
if it says "unpaused" for the Status. If it does, then execute the
ping of the IP Address above it. If it says anything other than
Unpaused, I can ignore that IP address (there would be no need to ping
it).

Target: 192.168.1.10:443
Status: unpaused
I would need to ping 192.168.1.10.

Target: 192.168.1.99:443
Status: paused
I would not need to ping 192.168.1.99

I tried doing Googling this problem, and I found references to
'backreferenes' in RegExp, and a whole host of other things that just
confused me. It also seems that the regexp functions vary from
language to language, because one of the solutions I tried for IP
Address before your reply was:
\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4]
[0-9]|[01]?[0-9][0-9]?)\b
Which is supposed to match IP Address formats very strictly, but when
I tried that, I received errors such as:
invalid command name "0-5"
while executing
"0-5"
invoked from within
"expect {
-re "\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.)
{3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b" {
..."
("while" body line 2)
invoked from within
"while {$done != 1} {
expect {
-re "\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.)
{3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)..."
(file "./test4" line 61)

But I digress... Thanks again for your help. The non-strict format
you gave me will work just fine, because if there is an invalid IP
Address in there, we have bigger problems.

Thanks,
Dan

Dan:
you could, since you have sufficient markers let expect get the bulk
and then parse with regexp

expect {
-i $myspawnid
-re {Target:.*unpaused} {
set buffer $expect_out(buffer)
regexp {Target:([^:]*):([^:]*)} $buffer match ipaddr
port
set status unpaused
ping $ipaddr $port $status
}
-re {Target:.*paused} {
set buffer $expect_out(buffer)
regexp {Target:([^:]*):([^:]*)} $buffer match ipaddr
port
set status paused
ping $ipaddr $port $status
}
eof {
puts stderr "Eof "
}
timeout {
puts stderr "Timeout"
}
}

Carl

.



Relevant Pages

  • network slowness/freez-up since update 10/11
    ... network problems: first the network is slow (even within a few ... network - but not the rest of the system - just locks up (can't ping ... OHCI version 1.0, legacy support ... <Parallel port bus> on ppc0 ...
    (freebsd-current)
  • network slowness/freez-up since update 10/11
    ... network problems: first the network is slow (even within a few ... network - but not the rest of the system - just locks up (can't ping ... OHCI version 1.0, legacy support ... <Parallel port bus> on ppc0 ...
    (freebsd-current)
  • network slowness/freez-up since update 10/11
    ... network problems: first the network is slow (even within a few ... network - but not the rest of the system - just locks up (can't ping ... OHCI version 1.0, legacy support ... <Parallel port bus> on ppc0 ...
    (freebsd-current)
  • RE: ICMP (Ping)
    ... Why do you assume that out of millions of Ips that respond, ... > almost) running a port scan those that reply. ... replies from a ping request. ... IP ranges with no target in mind, ...
    (Security-Basics)
  • RE: ICMP (Ping)
    ... script to locate vulnerabilities(example point and case: ... Is it good to allow UDP ping packets? ... Guys again, I am not saying that you disable pings and walk away, job ... 300K and you guys are right, it port scans like a freaking demon. ...
    (Security-Basics)