Question: Python function same _ subnetconverts IP addresses and subnet mask to binary strings in order to determine if two IPv 4 addresses are in the
Python function samesubnetconverts IP addresses and subnet mask to binary strings in order to determine if two IPv addresses are in the same subnet, returning a string indicating whether both IP addresses are in the same subnet or not.
Complete the Python function samesubnet. The function should accept three strings representing two IP addresses and a subnet mask, determine if both IP addresses are in the same subnet, and return a predefi ned string statement indicating if both IP addresses are in the same subnet. def samesubnetip ip subnetmask:
# convert IP addresses to binary strings
ipbin joinformatintxb for x in ipsplit
ipbin joinformatintxb for x in ipsplit
# convert subnet mask to binary string
subnetbin joinformatintxb for x in subnetmask.split
# get network address portion for both IP addresses
subnetlen subnetbin.count
networkbin ipbin:subnetlen
networkbin ipbin:subnetlen
# Predefined statement indicating if IP addresses are in the same subnet
x fip and ip are in the same subnet"
y fip and ip are not in the same subnet"
# Write a conditional expression to check if both IP addresses are in the same subnet
# and return the appropriate string output x or y
# Write your code here.
# You may alter the code below to test your solution or print help documentation.
# Only the samesubnet function will be graded for this assessment.
# printsamesubnet
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
