What's wrong with my Python code. We have to find the regularexpression in Python My output...

90.2K

Verified Solution

Question

Programming

What's wrong with my Python code. We have to find theregularexpression in Python My output should look like this

My IP address 128. 0. 0. 1

My IP address 53. 20. 62. 201

My code

ipAddresses = []

ipRegEx = re.compile(r\"\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}\")

   result = myRegEx.find all(Search Text)

   def Regular_expression(ipAddresses)

      for i in ipAddresses:

         print(i)

ipSearchResult = ipRegEx.search(line)

   if ipSearchResult != None andipSearchResult.group() not in ipAddresses:

      ipAddresses.append(ipSearchResult.group())

we have to use loop too.

Answer & Explanation Solved by verified expert
4.0 Ratings (802 Votes)
This modified code will fetch the IP addresses The module re should be imported to handle the regular expression The module socket should be imported to find the IP Addresses The statement ipAddresses socketgethostbynameexsocketgethostname fetches all the active IP addresses and assign it to the variable The    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students