Python Forum
extracting embedded IP addresses
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
extracting embedded IP addresses
#1
i am reading in a sequence of lines from a file. each line has zero or more (usually at least one) IPv4 addresses embedded within other text. there may be no space before or after the IPv4 address, but, there is never a decimal digit immediately adjacent to the IPv4 address. is there any code that extract just the IPv4 addresses from such a string and return a list of them (an empty list if there are not any)? else i'll write my own.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
First idea that comes to mind is that extract any sequence resembling IP address (by using regex, split, groupby or any other appropriate tool) and and then try to create instance of ip address.
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply
#3
Maybe have a look here: https://www.regular-expressions.info/ip.html
Reply
#4
(Aug-30-2019, 07:33 AM)ThomasL Wrote: Maybe have a look here: https://www.regular-expressions.info/ip.html

funny part where it might match some foreign numbers like Arabic ... ١٢٣.١٢٣.١٢٣.١٢٣ (123.123.123.123)

but what does \b do? they don't explain why that is there or make it be a link to a description. if they mean blank space then this is not what i want and i wonder if it can work without them.

there is a system function (with methods in os) that can tell you if a string is a valid IPv4 address (also a way to check for IPv6). my first plan was to call it at every position in a string in all lengths in range(1,16).
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  regex for addresses, dates, and times metulburr 2 2,249 Jun-29-2019, 01:11 AM
Last Post: ichabod801
  ipv6 addresses Skaperen 0 1,654 May-16-2019, 05:37 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020