Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
i need someone to help me make a program which would make combinations and transfer them into a .txt file but the combinations would have to be from 1.1.1.1 to 255.255.255.255( all of the possible ip addresses).for example, 1.1.1.1,1.1.1.2,1.1.1.3( it would take a lifetime!! I am begging someone to come up with this program/code and send it to me
birdie on birdie.co.nr

That is a programming 101 task. It's also so useless that it must be homework.
Better be careful or we'll whip out the 7407 on you!!
Be sure to come back and let us know if our suggestions helped!

I'll give you a hint:
four for loops and one printf
Be sure to come back and let us know if our suggestions helped!

lol :-D gotta love that 7407 post =-D and why is it that homework really is always useless? lol.
I think I know how to do this cause i remember my book was talking about it and used a mile counter as an example :)
GIMPS

Birdie - Have you spent time thinking abount the problem and results?
It doesn't take a lifetime. To find all the combinations took me about 30 minutes (Did not save or display the results) Celeron 466 Win 98 SE (PowerBasic DOS 3.1 in DOS Window [sorry, I don't do C++, see response 2 for solution]) running concurrently with DSL broadband file download.
How are you submitting your .txt file?
For your edification.
Number of IP Addresses - 4,228,250,625
File Length - 64,717,106,625 Bytes (65 GB)
(3 periods + 2 character separator)
File Size - 61,719 plus MB (62 GiB)
Pages - 13,482,731 plus unformatted pages
(80 character line x 60 lines per page)
Pages - 17,617,711 formatted pages
(4 columns x 60 rows per page)

Well, I'm a little late to this, but got started and for absolutely no reason wrote a program to do this in the best programming language ever (needs Win2000 or higher). Yes, I will freely give you the code, however there may be very slightly better ways to do this:
===============================================
@echo offset outfile=ip.txt
echo Starting...
echo Outputting to %outfile%
echo.
echo. > %outfile%set /a oct1 = -1
set /a oct2 = 0
set /a oct3 = 0
set /a oct4 = 1goto level1
:level4
echo %oct4%.%oct3%.%oct2%.-
if "%oct3%"=="256" set /a oct3 = 0
set /a oct4 += 1
echo %oct4%.%oct3%.%oct2%.%oct1% >> %outfile%
goto level1:level3
echo %oct4%.%oct3%.%oct2%.-
if "%oct2%"=="256" set /a oct2 = 0
set /a oct3 += 1
if "%oct3%"=="256" goto level4
echo %oct4%.%oct3%.%oct2%.%oct1% >> %outfile%
goto level1:level2
echo %oct4%.%oct3%.%oct2%.-
if "%oct1%"=="255" set /a oct1 = 0
set /a oct2 += 1
if "%oct2%"=="256" goto level3
echo %oct4%.%oct3%.%oct2%.%oct1% >> %outfile%:level1
set /a oct1 += 1
echo %oct4%.%oct3%.%oct2%.%oct1% >> %outfile%
if "%oct1%"=="255" if "%oct2%"=="255" if "%oct3%"=="255" if "%oct4%"=="255" goto end
if "%oct1%"=="255" goto level2
goto level1:end
echo.
echo Done.
pauseThere you go, though I wouldn't try to actually generate the file. As wizard points out, the file would be fairly large, and on my system it looks like it would take close to 200 days to generate. Fun!
What a waste of time... :/

Dr. Nick - I see that you too enjoy mental diversions. I wish the original poster of the question would come back with a reply. Questions like this occur several times a year. Not necessarily a waste of time. Only a waste if you start the project without some analysis.

Not necessarily a waste of time. Only a waste if you start the project without some analysis.
Hehe, I think for me this was strictly a waste of time :)
I have no idea why I started doing this as a batch file... sometimes my programming gets the best of me. If I start even a worthless project I have to finish it the same night I start it.
That said, I was curious just how much slower the batch file was than a standard C file. I wrote one up and found it was WAY FREAKING slower. Of course I couldn't just have a program without feedback, so I had to add percent complete and a little animation just to let you know it's working.
Bah, here it is. Any better ideas how to compute the percent done by using the current values of i, j, k, and l?
=====================================================
#include <stdio.h>int main()
{
FILE *f = fopen("ip.txt", "w");int i;
int j;
int k;
int l;unsigned int numDone = 0;
int count = 0;
int c;
char tmp = '-';printf("\nWriting file, use CTRL+C to stop...\n\n ");
//IPs range from 1.0.0.1 to 223.255.255.254
for (i=1; i<224; i++)
for (j=0; j<256; j++)
for (k=0; k<256; k++)
for (l=1; l<255; l++)
{
count++;
numDone++;if (count == 50000)
{
fflush(f);switch (tmp)
{
case '/':
tmp = '-';
break;
case '-':
tmp = '\\';
break;
case '\\':
tmp = '|';
break;
case '|':
tmp = '/';
}
printf("%7.3f%% done %c", (((double)numDone / 3712090112.0) * 100), tmp);
for (c=0; c<15; c++)
printf("\010");
count = 0;
}fprintf(f, "%d.%d.%d.%d\n", i, j, k, l);
}fclose(f);
return 0;
}Again, I'm sure this isn't the best code, but oh well :)

To find the percent.
The problem is that for each index the amount done is relative to the interations in each index. Each nested level adds [1/previous_level_total_iterations] to the amount completed.
ex. 1st index has 10 steps each step is worth 10%, 2nd index has 5 steps each step is worth [1/5] of the previous level [10%] or 2%.
Did it in spreadsheet to test methodology.
I'll stick it in my next project to show relative progress.

![]() |
Autorun CD command
|
help me please
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |