View Full Version : گرفتن رنج IP
ICEMAN
سه شنبه 09 بهمن 1386, 09:20 صبح
سلام ...
چطور میشه یا یه الگوریتمی برای بدست آوردن رنج IP و ...
IPv4
از: 192.168.0.1
تا: 192.168.5.254
یا مثلا برای IPv6
نمومه کد هم اگه بود که خیلی عالی میشه
ممنون
illegalyasync
سه شنبه 09 بهمن 1386, 12:12 عصر
سوالات مبهمه . اینکه گفتی خودش range بود
بدست آوردن رنج از چه چیزی ؟ کجا ؟
ICEMAN
سه شنبه 09 بهمن 1386, 14:54 عصر
سوالات مبهمه . اینکه گفتی خودش range بود
بدست آوردن رنج از چه چیزی ؟ کجا ؟
شاید باید میگفتم IP های توی یک Range ؟
مثلا بین 192.168.0.1 تا 192.168.100.254 چه IP هایی هستند این یه مثال برای IPv4بود همین مساله رو برای IPv6 هم میخوام.
امید وارم الان دیگه منظورم و گرفته باشد
TheMatrix
سه شنبه 09 بهمن 1386, 22:00 عصر
شاید باید میگفتم IP های توی یک Range ؟
مثلا بین 192.168.0.1 تا 192.168.100.254 چه IP هایی هستند این یه مثال برای IPv4بود همین مساله رو برای IPv6 هم میخوام.
امید وارم الان دیگه منظورم و گرفته باشد
الگوریتم: اول دوتا آی پی بگیر بعد اونا رو (هر آی پی رو) به چهار قسمتی که با نقطه جدا شده تقسیم کن بریز تو چهار تا متغیر عددی, بعد با چهار تا for تودرتو آی پی های بین range را بریز تو آرایه های char.
برای IPV6 هم همینطور ولی به شش قسمت و شش for تودرتو نیاز داری.
ICEMAN
پنج شنبه 11 بهمن 1386, 10:13 صبح
اینو از یه سایتی گرفتم همونیه که شما گفتید
ممنون از راهنماییتون
اگر برای IPv6 نمونه کدی پیدا کردید ممنون میشم اینجا هم بذارید
#include <iostream>
using namespace std;
/* here is a way to implement multi-ip scanning... */
//globals
char iphigh[15] = /* some inputted addy */
char iplow[15] = /* some inputted addy */
/* function for splitting ip addys */
int split(char array[15])
{
char splitarray[3];
int x;
int position = 0; /* start at the first position
for(x = 1 ; x < 4 ; x++){
splitarray[x] = 0; /* fill up the temp array so no empty spaces */
}
for(x = 1; x < 15 ; x++){
if( array[x] == '.' ){
position++; /* move to the next position in the array */
continue;
}
splitarray[position] = splitarray[position] + array[x];
/* will this eval as strings and concatenate? If not, this has to be changed. */
return splitarray;
}
// this function will actually start scanning the range of ip addys
void scanrange(char myiplow[15], char myiphigh[15])
{
/* counter vars */
int counter1;
int counter2;
int counter3;
int counter4;
/* address to scan */
char scanaddr[15];
int iphigh_split[3]; /* these are the portions of the ip after splitting, in 127.0.0.1,
"127" would be iphigh_split[0], "0" would be iphigh_split[1], "0"
would be iphigh_split[2], and "1" would be iphigh_split[3]. */
int iplow_split[3];
iphigh_split[] = split(myiphigh[15]); //splitting the ip addys
iplow_split[] = split(myiplow[15]); //splitting the ip addys
/* now the for() loops play use the split ip addys as counter upper and lower boundaries.
there are four parts to ip addresses, so there are four levels of nesting. */
for(counter1 = iplow_split[1] ; counter1 < iphigh_split[1] ; counter1++)
{ /*first nesting*/
for(counter2 = iplow_split[2] ; counter2 < iphigh_split[2] ; counter2++)
{ /*second nesting*/
for(counter3 = iplow_split[3] ; counter3 < iphigh_split[3] ; counter3++)
{ /*third nesting*/
for(counter4 = iplow_split[4] ; counter4 < iphigh_split[4] ; counter4++)
{ /*fourth nesting*/
/* create the address to scan */
scanaddr = counter1 + "." + counter2 + "." + counter3 + "." + counter4;
/* put in socket connectivity functions here */
} /*end fourth nesting*/
} /*end third nesting*/
} /*end second nesting*/
} /*end first nesting*/
return 1;
}
/* I hope this helps... */
int main()
{
return 0;
}
vBulletin® v4.2.5, Copyright ©2000-1404, Jelsoft Enterprises Ltd.