2

List of Private IPs are noted below

10.0.0.0 – 10.255.255.255    
172.16.0.0 – 172.31.255.255     
192.168.0.0 – 192.168.255.255

I have a dataframe with one column called IP_Address. I want to create another column called IP_Type with the value being either Public or Private

How do I proceed to execute this?

This is what I have below:

IP_Address
----------
68.168.102.50
185.175.32.166
77.160.161.171
94.47.147.90
110.36.82.74
88.231.25.35
188.159.36.111
201.158.110.171

So far I have broken it down like this

#Private IPs in the 10 range
drill=df[0].str.split('.',expand=True)
ten= drill.loc[(drill[0] == "10") & (drill[1] <= "255") & (drill[2] <= "255") & (drill[3] <= "255")]
jreyez
  • 171
  • 3
  • 4
  • 15
  • 5
    Trying to do address manipulation in text is fraught with problems. IPv4 addresses are 32-bit integers, and you should treat them that way. You can convert them to integers and then easily compare to see if they are in the `10.0.0.0/8`, `172.16.0.0/12`, or `192.168.0.0/16` networks. The math of how to specifically see if addresses are in a particular network is detailed in [this two-part answer](https://networkengineering.stackexchange.com/a/53994/8499). – Ron Maupin Mar 04 '19 at 21:03
  • Maybe you can use some ideas and links of this answer: https://stackoverflow.com/a/54889631/1498199 – JoergVanAken Mar 04 '19 at 22:31

0 Answers0