Hi people,
How can I find a IP adress in a string using regexp?
Received: from unknown (HELO u7b3u5) (naxata@200.228.69.237 with login)
Thanks to all.
|
|
0
|
|
|
|
Reply
|
vinicius (2)
|
1/9/2004 2:17:35 PM |
|
vinicius@sordido.com.br (Vinicius) wrote in
news:6c8acc33.0401090617.6d618d53@posting.google.com:
> How can I find a IP adress in a string using regexp?
>
> Received: from unknown (HELO u7b3u5) (naxata@200.228.69.237 with login)
I'll answer this if you can tell me what this has to do with the C
language.
--
- Mark ->
--
|
|
0
|
|
|
|
Reply
|
nospam243 (468)
|
1/9/2004 2:19:37 PM
|
|
begin followup to Mark A. Odell:
> I'll answer this if you can tell me what this has to do with
> the C language.
Apart from time travel C is not very useful. Use perl instead.
$ perl -ne 'm/\d+\.\d+\.\d+\.\d+/ && print $&' < data
200.228.69.237
--
F�r Google, Tux und GPL!
|
|
0
|
|
|
|
Reply
|
alexander.bartolich (131)
|
1/9/2004 3:16:05 PM
|
|
Alexander Bartolich wrote:
> begin followup to Mark A. Odell:
>> I'll answer this if you can tell me what this has to do with
>> the C language.
>
> Apart from time travel C is not very useful. Use perl instead.
>
> $ perl -ne 'm/\d+\.\d+\.\d+\.\d+/ && print $&' < data
> 200.228.69.237
Why do people keep posting broken perl "solutions" to comp.lang.c?
$ perl -ne 'm/\d+\.\d+\.\d+\.\d+/ && print $&' <<< 12345.12345.12345.12345
12345.12345.12345.12345
"Some people, when confronted with a problem, think ``I know, I'll
use regular expressions.'' Now they have two problems." - JWZ
Jeremy.
|
|
0
|
|
|
|
Reply
|
jeremy63 (294)
|
1/9/2004 3:50:05 PM
|
|
Alexander Bartolich wrote:
> begin followup to Mark A. Odell:
>
>>I'll answer this if you can tell me what this has to do with
>>the C language.
>
>
> Apart from time travel C is not very useful. Use perl instead.
>
> $ perl -ne 'm/\d+\.\d+\.\d+\.\d+/ && print $&' < data
> 200.228.69.237
>
Not useful? Funny that you'll still need C to compile the PERL
processor, see perl.c in the PERL distribution :)
Seth
~ Let us linux ~
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
|
|
0
|
|
|
|
Reply
|
chevystm (6)
|
1/9/2004 4:12:31 PM
|
|
begin followup to Jeremy Yallop:
> Why do people keep posting broken perl "solutions" to comp.lang.c?
Because it's fun.
perl -ne 'm/\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/ && print $&' < data
> "Some people, when confronted with a problem, think ``I know, I'll
> use regular expressions.'' Now they have two problems." - JWZ
--
# The Slam Dunk Answer
# They can go with me, or they can go with you, or they can go nowhere.
# But gee, the last two options are the same.
-- Larry Wall in <1994Jul28.193540.9498@netlabs.com>
|
|
0
|
|
|
|
Reply
|
alexander.bartolich (131)
|
1/9/2004 7:56:30 PM
|
|
Alexander Bartolich wrote:
> begin followup to Jeremy Yallop:
>> Why do people keep posting broken perl "solutions" to comp.lang.c?
>
> Because it's fun.
>
> perl -ne 'm/\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/ && print $&' < data
Still broken. It wrongly accepts "333.444.555.666" (and doesn't
recognize "_127.0.0.1_", which perhaps it should).
Jeremy.
|
|
0
|
|
|
|
Reply
|
jeremy63 (294)
|
1/9/2004 8:21:09 PM
|
|
begin followup to Jeremy Yallop:
> Still broken. It wrongly accepts "333.444.555.666"
Well, inet_aton has to be good for something. And whether the
overhead of a regular expression is better than than a brute
force loop with strstr ... is really just another kind of dick
sizw war.
> (and doesn't recognize "_127.0.0.1_", which perhaps it should).
By the same logic you can say it should also recognize IPv6.
But then who knows what the OP really wants.
--
F�r Google, Tux und GPL!
|
|
0
|
|
|
|
Reply
|
alexander.bartolich (131)
|
1/9/2004 9:48:29 PM
|
|
Alexander Bartolich wrote:
> begin followup to Jeremy Yallop:
>> Still broken. It wrongly accepts "333.444.555.666"
>
> Well, inet_aton has to be good for something. And whether the
> overhead of a regular expression is better than than a brute
> force loop with strstr ... is really just another kind of dick
> sizw war.
Correctness, not overhead, is the primary issue. All the code in this
thread that uses regular expressions has been hopelessly broken. This
isn't the right place to debug Perl code, though, as pointed out
already.
Jeremy.
|
|
0
|
|
|
|
Reply
|
jeremy63 (294)
|
1/9/2004 10:21:21 PM
|
|
Alexander Bartolich <alexander.bartolich@gmx.at> writes:
> begin followup to Jeremy Yallop:
> > Why do people keep posting broken perl "solutions" to comp.lang.c?
>
> Because it's fun.
>
> perl -ne 'm/\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/ && print $&' < data
Not really. The above solution recognizes many things that look like
IP addresses, but are invalid. It may also fail to recognize some
things that are valid IP addresses. I won't go into the details,
because this (a) isn't the right place for it, and (b) I'm not sure of
the exact definition of a valid IP address (or, rather, of the textual
representation of a valid IP address).
The use of Perl is obviously off-topic, but a complete response would
require discussion of the RFC or RFCs that define the format, and
would probably veer off into IPV6 issues as well. If I tried to
discuss it here, I would miss the opportunity to have my inevitable
mistakes corrected by experts.
C has no built-in support for regular expressions, though of course
numerous regular expression packages have been written in C.
If you want to present a definition of a valid IP address and ask how
to recognize strings that match the definition in portable C, this is
the place to discuss it -- ideally by posting a short working code
sample and asking why it doesn't work. Otherwise, there are more
appropriate newsgroups.
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://www.sdsc.edu/~kst>
Schroedinger does Shakespeare: "To be *and* not to be"
|
|
0
|
|
|
|
Reply
|
kst-u (21549)
|
1/9/2004 10:54:13 PM
|
|
begin followup to Jeremy Yallop:
> Correctness, not overhead, is the primary issue.
This is a meaningless sequence of buzzwords.
Correctness primarily requires a correct definition of correctness.
> All the code in this thread that uses regular expressions has
> been hopelessly broken.
No other code has been posted. Ok, this may be because the whole
issue is way off-topic. Aggravated by severe immunity against
trolling amongst regulars.
Anyway, the funny thing about your definition of 'hopeless' is
how little change is required after each redefinition of the task
at hand.
#!/usr/bin/perl -wn
BEGIN { use Socket; }
m/\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/ && inet_aton($&) && print $&;
--
The Paternal Patter Answer
# That's okay, <name>, I understand where you're coming from.
# I once went through the rebellious stage you're going through,
# but eventually I settled down and started getting some real work
# done. These things just take time. Be patient with yourself.
-- Larry Wall <1994Jul28.193540.9498@netlabs.com>
|
|
0
|
|
|
|
Reply
|
alexander.bartolich (131)
|
1/9/2004 10:59:04 PM
|
|
vinicius@sordido.com.br (Vinicius) wrote:
# Hi people,
#
# How can I find a IP adress in a string using regexp?
#
# Received: from unknown (HELO u7b3u5) (naxata@200.228.69.237 with login)
tclsh <<':eof'
set d {([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])}
set p {[.]}
set string {Received: from unknown (HELO u7b3u5) (naxata@200.228.69.237 with login)}
if {[regexp $d$p$d$p$d$p$d $string ip]} {
puts $ip
}
:eof
--
Derk Gwen http://derkgwen.250free.com/html/index.html
Title does not dictate behaviour.
|
|
0
|
|
|
|
Reply
|
derkgwen (343)
|
1/9/2004 11:36:32 PM
|
|
Alexander Bartolich wrote:
> Anyway, the funny thing about your definition of 'hopeless' is
> how little change is required after each redefinition of the task
> at hand.
There has been no such redefinition.
> #!/usr/bin/perl -wn
[snip]
Sorry, but it's still both broken and off-topic.
Jeremy.
|
|
0
|
|
|
|
Reply
|
jeremy63 (294)
|
1/10/2004 7:30:49 PM
|
|
|
12 Replies
79 Views
(page loaded in 0.145 seconds)
Similiar Articles: IP address lookup with javascript? - comp.lang.javascript ...Hello, I would like to take a host name, and get its IP address, like take www.yahoo.com and get xxx.yyy.zzz.www, on a web page that runs across diff... Regex to match a numerical IP range - comp.lang.perl.misc ...I thought it was a neat exercise in utf8, eval, and regular expressions though. ... $ /x; } if ($ip =~ /$rx_IPRx/) { if ( defined $1 ... regex match multiple words in a line - comp.databases.mysql ...Overall, MySQL regular expression support is pretty weak. You may end up needing to something ... Regex to match a numerical IP range - comp.lang.perl.misc ... regex match ... how to code extract Ip address - comp.unix.solaris> > thanks > If all you want to do is extract IP addresses from a log file you can do it with grep, awk, nawk, or gawk. The regular expression would look something like ... Using regular expressions to split a string - comp.lang.javascript ...Using regular expressions, is it possible to ... Regex to match a numerical IP range - comp.lang.perl.misc ..... neat exercise in utf8, eval, and regular expressions ... grep for a "`g'"? (gives an "Unmatched `" err) - comp.unix.solaris ...So, the question becomes "how to write a REGEXP that will find them? Any clues? ... the diagnostic test ... to verify that a host entry is present: grep "IP ... how to match "$" in expect, instead of using it as a wildcard ...Regex to match a numerical IP range - comp.lang.perl.misc ... And for a ... Hi, I d like to use .NET regular expression class to find a whole-word match instead a substring ... list of regex special characters - comp.lang.pythonI am looking for a list of special character in python regular expressions that need to be ... Regex to match a numerical IP range - comp.lang.perl.misc ... list of regex ... regex for word in parentheses ? - comp.lang.tclRegex to match a numerical IP range - comp.lang.perl.misc ... regex for word ... inside round brackets or parentheses, you can group that part of the regular expression ... Awk Regex Syntax / Flavor? - comp.lang.awkRegex to match a numerical IP range - comp.lang.perl.misc ... Awk Regex Syntax ... the GNU BRE and ERE syntax, and other regex flavors. ... traditional regular expression ... Help to 'pretty'; replace WITHIN file without TEMP file?? - comp ...... just ask (I'm particularly concerned that my use of a match to a regular expression as a ... FY<YEAR>\MMM\Day-6*.xls" INC,NONREC; REPSET RULE ADD "F:\Bal_Sheets\IP ... Javascript search engine - comp.lang.javascriptMy IP Address, Whoami: Whois: Mail Exchanger (MX Record) Lookup ... trim whitespace - LTRIM/RTRIM/TRIM? - comp ... COMPGROUPS.NET Search ... Using Regular Expressions ... Gawk Newbe Syntax Trouble - comp.lang.awkBe aware '~' is not the same as '==', but ~ // allows regexp magic. > >Can you guys ... There is the gawk manual describing the TCP/IP interface of gawk: http://www.gnu ... any limits on the size of the iTunes library? - comp.sys.mac.apps ...COMPGROUPS.NET | Search ... for it in your local library. So to ... in regular expressions ... ... curious if there are any limitations of IP ... How do i extract data from a pdf document using code - comp.text ...... can also use the PDF javascript to do the low-level text extraction and regular expression ... extract Ip address - comp.unix.solaris How can I code a routine to extract Ip ... Regular Expression ExamplesTo restrict all 4 numbers in the IP address to 0..255, you can use this ... Use regular expressions to search through large numbers of text and binary files. Regexp: Private IP AddressesIs there any regexp to recognize private IP Addresses? I didn't find in Regexp-Common. 7/18/2012 5:12:49 AM
|