Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Bula Vinaka
Oct 21, 2020

beach side
I have a CSV file with IPv4 ranges in it, that I built from IP2Location's IP2Location LITE IP-COUNTRY-REGION-CITY-LATITUDE-LONGITUDE Database:

https://lite.ip2location.com/database/db5-ip-country-region-city-latitude-longitude
(Download -> IPv4 Database -> CSV Format)

This is the closest I can get the file into the format that I need (5 example lines):

62.56.193.0,62.56.194.255,Pinar de Chamartin,Madrid Comunidad de,ES,40.479030,-3.668360
62.56.195.0,62.56.195.255,Lora del Rio,Andalucia,ES,37.658960,-5.527510
62.56.196.0,62.56.196.255,Lodosa,Navarra Comunidad Foral de,ES,42.422690,-2.077410
62.56.197.0,62.56.197.255,San Vicente de la Barquera,Cantabria,ES,43.385090,-4.399340
62.56.198.0,62.56.198.255,Gandia,Valenciana Comunidad,ES,38.966667,-0.183333

What I need, is to convert each line above, into 256 separate lines, so that there is a single IP address per line. (That would convert the above 5 line example into 1280 lines.)

So for example, let's take one line from the above:

62.56.196.0,62.56.196.255,Lodosa,Navarra Comunidad Foral de,ES,42.422690,-2.077410

I need to turn that one line, into the following 256 lines:

62.56.196.0,Lodosa,Navarra Comunidad Foral de,ES,42.422690,-2.077410
62.56.196.1,Lodosa,Navarra Comunidad Foral de,ES,42.422690,-2.077410
62.56.196.2,Lodosa,Navarra Comunidad Foral de,ES,42.422690,-2.077410
62.56.196.3,Lodosa,Navarra Comunidad Foral de,ES,42.422690,-2.077410
...
62.56.196.255,Lodosa,Navarra Comunidad Foral de,ES,42.422690,-2.077410

Would would be best, is some kind program or script, that can automatically write me a new file, going line by line, converting each line into 256 separate lines with one IP address per line. (The file would end up being 50 gigs or so in size by my estimate... that's perfectly OK.)

Is there anyway I can do this with an application? I'm not bright enough with programming to figure out myself how to do this with Python, Javascript, etc. I would need someone else to show me how, step by step unfortunately.

Adbot
ADBOT LOVES YOU

Canine Blues Arooo
Jan 7, 2008

when you think about it...i'm the first girl you ever spent the night with

Grimey Drawer
I made a thing that'll probably do this. This is hackjob, but it'll probably work.

Download here

Extract to some dir. Make sure your csv is in the same directory as the executable/dll/runtime json. Requires .NET 6 (I can target .NET Framework if need be) Invoke from command line as such:

code:
 C:\Users\MyUserName\Desktop\ExampleDir> ipCSVConvert.exe myInput.csv 
Output will be SavedLists.txt in the same directory

Let me know if it falls over and I can probably fix it.

Canine Blues Arooo fucked around with this message at 09:12 on Sep 12, 2022

Bula Vinaka
Oct 21, 2020

beach side
OMG, **THANKS SO MUCH** !!!

I didn't expect this. This is great!!

BUT...

It didn't work, mainly because it ran out of memory. It looks like the app writes all of its output to RAM first, before going to a file, so, it runs out of RAM when processing the entire file (I have 56 GB).

The other problem, is that it misses one x.x.x.255 IP per line.

So for the following test list:

code:
1.0.0.0,1.0.0.255,Los Angeles,California,US,34.052859,-118.243570
1.0.1.0,1.0.3.255,Fuzhou,Fujian,CN,26.061390,119.306110
1.0.4.0,1.0.4.255,Glebe,Tasmania,AU,-42.874710,147.328130
1.0.5.0,1.0.7.255,Melbourne,Victoria,AU,-37.814000,144.963320
1.0.8.0,1.0.15.255,Guangzhou,Guangdong,CN,23.127361,113.264250
1.0.16.0,1.0.31.255,Tokyo,Tokyo,JP,35.689506,139.691700
1.0.32.0,1.0.63.255,Guangzhou,Guangdong,CN,23.127361,113.264250
1.0.64.0,1.0.67.255,Hiroshima,Hiroshima,JP,34.385280,132.455280
1.0.68.0,1.0.68.255,Sendai,Miyagi,JP,38.267000,140.867000
1.0.69.0,1.0.71.255,Hiroshima,Hiroshima,JP,34.385280,132.455280
1.0.72.0,1.0.72.255,Niho,Hiroshima,JP,34.369940,132.493950
1.0.73.0,1.0.79.255,Hiroshima,Hiroshima,JP,34.385280,132.455280
1.0.80.0,1.0.80.255,Izumo,Shimane,JP,35.367000,132.767000
1.0.81.0,1.0.81.255,Hikari,Yamaguchi,JP,33.961940,131.942220
1.0.82.0,1.0.82.255,Matsue,Shimane,JP,35.467000,133.050000
1.0.83.0,1.0.83.255,Kurayoshi,Tottori,JP,35.433000,133.817000
1.0.84.0,1.0.84.255,Tottori,Tottori,JP,35.500000,134.233000
1.0.85.0,1.0.85.255,Matsue,Shimane,JP,35.467000,133.050000
1.0.86.0,1.0.86.255,Hikari,Yamaguchi,JP,33.961940,131.942220
1.0.87.0,1.0.87.255,Yamaguchi,Yamaguchi,JP,34.183000,131.467000
1.0.88.0,1.0.88.255,Yonago,Tottori,JP,35.433000,133.333000
1.0.89.0,1.0.89.255,Kurayoshi,Tottori,JP,35.433000,133.817000
1.0.90.0,1.0.90.255,Tottori,Tottori,JP,35.500000,134.233000
1.0.91.0,1.0.91.255,Izumo,Shimane,JP,35.367000,132.767000
1.0.92.0,1.0.92.255,Hikari,Yamaguchi,JP,33.961940,131.942220
1.0.93.0,1.0.93.255,Hiroshima,Hiroshima,JP,34.385280,132.455280
1.0.94.0,1.0.94.255,Yonago,Tottori,JP,35.433000,133.333000
1.0.95.0,1.0.95.255,Kurayoshi,Tottori,JP,35.433000,133.817000
1.0.96.0,1.0.96.255,Hikari,Yamaguchi,JP,33.961940,131.942220
1.0.97.0,1.0.97.255,Izumo,Shimane,JP,35.367000,132.767000
1.0.98.0,1.0.99.255,Yamaguchi,Yamaguchi,JP,34.183000,131.467000
1.0.100.0,1.0.100.255,Izumo,Shimane,JP,35.367000,132.767000
1.0.101.0,1.0.101.255,Matsue,Shimane,JP,35.467000,133.050000
1.0.102.0,1.0.103.255,Yamaguchi,Yamaguchi,JP,34.183000,131.467000
1.0.104.0,1.0.104.255,Hikari,Yamaguchi,JP,33.961940,131.942220
1.0.105.0,1.0.105.255,Matsue,Shimane,JP,35.467000,133.050000
1.0.106.0,1.0.106.255,Tottori,Tottori,JP,35.500000,134.233000
1.0.107.0,1.0.107.255,Yamaguchi,Yamaguchi,JP,34.183000,131.467000
1.0.108.0,1.0.108.255,Okayama,Okayama,JP,34.650000,133.917000
1.0.109.0,1.0.109.255,Hiroshima,Hiroshima,JP,34.385280,132.455280
1.0.110.0,1.0.110.255,Izumo,Shimane,JP,35.367000,132.767000
1.0.111.0,1.0.111.255,Matsue,Shimane,JP,35.467000,133.050000
1.0.112.0,1.0.113.255,Yonago,Tottori,JP,35.433000,133.333000
1.0.114.0,1.0.114.255,Kurayoshi,Tottori,JP,35.433000,133.817000
1.0.115.0,1.0.115.255,Shimonoseki,Yamaguchi,JP,33.950000,130.933000
1.0.116.0,1.0.117.255,Izumo,Shimane,JP,35.367000,132.767000
1.0.118.0,1.0.118.255,Tottori,Tottori,JP,35.500000,134.233000
1.0.119.0,1.0.119.255,Izumo,Shimane,JP,35.367000,132.767000
1.0.120.0,1.0.120.255,Yonago,Tottori,JP,35.433000,133.333000
 
 
The following IP's are only expanded to x.x.x.254, and are missing the last x.x.x.255 line:

code:
1.0.0.254,Los Angeles,California,US,34.052859,-118.243570
1.0.3.254,Fuzhou,Fujian,CN,26.061390,119.306110
1.0.4.254,Glebe,Tasmania,AU,-42.874710,147.328130
1.0.7.254,Melbourne,Victoria,AU,-37.814000,144.963320
1.0.15.254,Guangzhou,Guangdong,CN,23.127361,113.264250
1.0.31.254,Tokyo,Tokyo,JP,35.689506,139.691700
1.0.63.254,Guangzhou,Guangdong,CN,23.127361,113.264250
1.0.67.254,Hiroshima,Hiroshima,JP,34.385280,132.455280
1.0.68.254,Sendai,Miyagi,JP,38.267000,140.867000
1.0.71.254,Hiroshima,Hiroshima,JP,34.385280,132.455280
1.0.72.254,Niho,Hiroshima,JP,34.369940,132.493950
1.0.79.254,Hiroshima,Hiroshima,JP,34.385280,132.455280
1.0.80.254,Izumo,Shimane,JP,35.367000,132.767000
1.0.81.254,Hikari,Yamaguchi,JP,33.961940,131.942220
1.0.82.254,Matsue,Shimane,JP,35.467000,133.050000
1.0.83.254,Kurayoshi,Tottori,JP,35.433000,133.817000
1.0.84.254,Tottori,Tottori,JP,35.500000,134.233000
1.0.85.254,Matsue,Shimane,JP,35.467000,133.050000
1.0.86.254,Hikari,Yamaguchi,JP,33.961940,131.942220
1.0.87.254,Yamaguchi,Yamaguchi,JP,34.183000,131.467000
1.0.88.254,Yonago,Tottori,JP,35.433000,133.333000
1.0.89.254,Kurayoshi,Tottori,JP,35.433000,133.817000
1.0.90.254,Tottori,Tottori,JP,35.500000,134.233000
1.0.91.254,Izumo,Shimane,JP,35.367000,132.767000
1.0.92.254,Hikari,Yamaguchi,JP,33.961940,131.942220
1.0.93.254,Hiroshima,Hiroshima,JP,34.385280,132.455280
1.0.94.254,Yonago,Tottori,JP,35.433000,133.333000
1.0.95.254,Kurayoshi,Tottori,JP,35.433000,133.817000
1.0.96.254,Hikari,Yamaguchi,JP,33.961940,131.942220
1.0.97.254,Izumo,Shimane,JP,35.367000,132.767000
1.0.99.254,Yamaguchi,Yamaguchi,JP,34.183000,131.467000
1.0.100.254,Izumo,Shimane,JP,35.367000,132.767000
1.0.101.254,Matsue,Shimane,JP,35.467000,133.050000
1.0.103.254,Yamaguchi,Yamaguchi,JP,34.183000,131.467000
1.0.104.254,Hikari,Yamaguchi,JP,33.961940,131.942220
1.0.105.254,Matsue,Shimane,JP,35.467000,133.050000
1.0.106.254,Tottori,Tottori,JP,35.500000,134.233000
1.0.107.254,Yamaguchi,Yamaguchi,JP,34.183000,131.467000
1.0.108.254,Okayama,Okayama,JP,34.650000,133.917000
1.0.109.254,Hiroshima,Hiroshima,JP,34.385280,132.455280
1.0.110.254,Izumo,Shimane,JP,35.367000,132.767000
1.0.111.254,Matsue,Shimane,JP,35.467000,133.050000
1.0.113.254,Yonago,Tottori,JP,35.433000,133.333000
1.0.114.254,Kurayoshi,Tottori,JP,35.433000,133.817000
1.0.115.254,Shimonoseki,Yamaguchi,JP,33.950000,130.933000
1.0.117.254,Izumo,Shimane,JP,35.367000,132.767000
1.0.118.254,Tottori,Tottori,JP,35.500000,134.233000
1.0.119.254,Izumo,Shimane,JP,35.367000,132.767000
1.0.120.254,Yonago,Tottori,JP,35.433000,133.333000
 
 
There are 49 IP's in both the first and second lists, and the cities/countries/long/lat all line up in both lists, so it appears to only go to x.x.x.254 in one IP range per source line. I believe it is the last range, if there are more than one range per line. (Check the 4th one up from the bottom in the first list, it has 1.0.116.0 - 1.0.117.255, so your tool does go to 1.0.116.255, but only to 1.0.117.254.)

I checked and the results of this are repeatable (meaning it gives the exact same results every time as opposed to being a random thing.)

For the RAM problem, I can just do the file in sections. But I'm not sure if there's an easy "search and replace" way to take care of the x.x.x.255 issue. If you don't feel like doing any additional work for this for free, I understand! But please PM me anyways if you have a Buy Me a Coffee or anything like that!

Again, I can't thank you enough!

(P.S. - I'm using the Microsoft .NET Windows Runtime 6.0.8)

Bula Vinaka fucked around with this message at 12:48 on Sep 12, 2022

Canine Blues Arooo
Jan 7, 2008

when you think about it...i'm the first girl you ever spent the night with

Grimey Drawer
The off by one is a trivial fix.

I can also fix the memory issue here as well relatively easily - stand by

Bula Vinaka
Oct 21, 2020

beach side
I don't think I ever asked a question like this on a forum, reddit, etc., and had someone actually write me a custom exe like this. I can't thank you enough!

:dance:

Canine Blues Arooo
Jan 7, 2008

when you think about it...i'm the first girl you ever spent the night with

Grimey Drawer
Alright, I yolo'd some fixes here:

Download here

Should fix the off by one error. I'm not testing against the entire IPv4 list, but I'm 80% sure the memory issue is addressed. I have no idea what performance on File.Append on a large file is (or if it even matters) so uh...hopefully it's fine.

Canine Blues Arooo fucked around with this message at 18:44 on Sep 12, 2022

Adbot
ADBOT LOVES YOU

Bula Vinaka
Oct 21, 2020

beach side
It works!!!

Thanks so much, you're awesome.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply