title: How to filter ip public and ip private with python
body: <p>i have a file (list_ip.txt) which contains only public ip lists and ip private. I want to split one file into 2 files. one file (ip_public.txt) contains public ip, one file (ip_private.txt) again contains ip private. how do i do it?
  contents of ip_list.txt :</p>
  
  <pre><code>192.168.14.43
  104.244.xxx.xxx
  192.168.10.54
  38.102.xxx.xxx
  192.168.13.232
  144.217.xxx.xxx
  10.100.40.93
  54.171.xxx.xxx
  10.100.xxx.xxx
  183.61.xxx.xxx
  10.100.xxx.xxx
  136.243.xxx.xxx
  10.40.xxx.xxx
  185.75.xxx.xxx
  </code></pre>
  
  <p>this is my code :</p>
  
  <pre><code>import csv
  
  file = open('list_ip.txt', 'r')
  ipprivate = open('ip_private.txt', 'w')
  ippublic = open('ip_public.txt', 'w')
  
  def ipRange(start_ip, end_ip):
      start = list(map(int, start_ip.split(".")))
      end = list(map(int, end_ip.split(".")))
  
      for i in range(4):
          if start[i] &gt; end[i]:
              start, end = end, start
          break
  
      temp = start
      ip_range = []
  
      ip_range.append(start_ip)
      while temp != end:
      start[3] += 1
      for i in (3, 2, 1):
          if temp[i] == 256:
              temp[i] = 0
              temp[i-1] += 1
              ip_range.append(“.”.join(map(str, temp))
  )
  
      return ip_range
  
  iprange = ipRange("192.168.0.0","192.168.255.255")
  iprange2 = ipRange("172.16.0.0","172.31.255.255")
  iprange3 = ipRange("10.0.0.0","10.255.255.255")
  
  for line in file:
      if line == iprange:
          ipprivate.write(line)
      if line == iprange2:
          ipprivate.write(line)
      if line == iprange3:
          ipprivate.write(line
      else:
          ippublic.write(line)
  file.close()
  ipprivate.close()
  ippublic.close()
  </code></pre>