首页
社区
课程
招聘
[原创][原创]IP地址生成IP地址生成C++
发表于: 2012-1-23 21:35 6865

[原创][原创]IP地址生成IP地址生成C++

2012-1-23 21:35
6865
[原创]IP地址生成IP地址生成C++
[原创]IP地址生成C++

玉面飞龙     BY: http://hi.baidu.com/alalmn
QQ 群30096995
TIME:2012-1-23
IP地址生成有2种
一种是随机生成
另外一种是设置头和尾生成的  2种我都公布下吧

一种是随机生成
//用随机数组成一个IP,并存入文件中
#include <iostream.h>
#include <time.h>
#include<windows.h>
#include <cstdlib>
#include<fstream.h>
#define M 10000

void main()
{
DWORD start=GetTickCount();
ofstream fout("d:\\生成的IP.txt",ios::trunc);
for(int i=0;i<M;i++)
{
  int t1,t2,t3,t4;
  t1 = rand()%255+1;
     t2 = rand()%255+1;
     t3 = rand()%255+1;
     t4 = rand()%255+1;
        cout << t1 <<"."<<t2<<"."<<t3<<"."<<t4<<endl;
     
     fout<< t1 <<'.'<<t2<<'.'<<t3<<'.'<<t4<<'\n';
  cout<<i<<endl;
}
fout.close();
cout<<"耗时%d毫秒:"<<GetTickCount()-start<<endl;
    return ;
}

另外一种是设置头和尾生成的  DELPHI 的大家自己转换成VC吧  我转换好了呵呵
procedure TForm1.IPR(A1,A2,A3,A4,B1,B2,B3,B4:integer);
begin
      repeat   //循环  没有满足  until   not一直循环
            form1.ListBox1.Items.Add(format('%d.%d.%d.%d ',[A1,A2,A3,A4]));  //添加listbox  (把A!2AA3按照%d.%d.%d.%d 连接)
            if   form1.ListBox1.Items.Count> 3000   then  //就是listbox的行数大于3000后就清空listbox
                form1.ListBox1.Items.Clear   ;  //清空

            inc(A4); //自加
            if   A4> 254   then  //当a4 小与254
            begin
                  A4:=1;//赋值
                inc(A3);  //自加
                  if   A3> 255   then ////当a3 小与254
                  begin
                        A3:=1;//赋值
                   inc(A2);  //自加
                        if   A2> 255   then
                        begin
                              A2:=1;
                              inc(A1);
                        end;
                  end;
            end;
            Application.ProcessMessages   ;  //应该是同时值行下面的程序
      until   not((A4   <   B4)   Or   (A3   <   B3)   Or   (A2   <   B2)   Or   (A1   <   B1));
//就是判断a4有没有到B4还有A3到没到B3...排下去
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  BeginIP,endIP:integer;
begin
  BeginIP:=IPStrToInt(trim(BeginIPed.text));
  BIP:=@BeginIP;   //开始IP
  endIP:=IPStrToInt(trim(EndIPed.Text));
  EIP:=@endIP;
  IPR(BIP.a,BIP.b,BIP.c,BIP.d,EIP.a,EIP.b,EIP.c,EIP.d);

end;

[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课

上传的附件:
收藏
免费 0
支持
分享
最新回复 (4)
雪    币: 107
活跃值: (326)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
2
不明白你是要干嘛??????????????????
2012-1-24 10:23
0
雪    币: 94
活跃值: (445)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
3
要生成随机IP的话,你这两种方法都不算快
2012-1-24 10:53
0
雪    币: 31
活跃值: (43)
能力值: ( LV3,RANK:20 )
在线值:
发帖
回帖
粉丝
4
貌似只是生成,并不设置成当前ip。
2012-1-24 13:00
0
雪    币: 219
活跃值: (38)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
5
有什么用??
2012-1-24 15:15
0
游客
登录 | 注册 方可回帖
返回
//