Found All IP from x.x.x.1 to x.x.x.256

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Smurfas
    New Member
    • Jul 2008
    • 30

    Found All IP from x.x.x.1 to x.x.x.256

    For example i need:
    123.123.123.1
    123.123.123.2
    ....
    123.123.123.256
    -------------------------------------------
    I write code:
    Code:
            
            for (int i = 0; i < IPadresas.Length; i++)
            {
                IPad_cut[i] = IPadresas[i];
                if (IPad_cut[i] == '.') { dotCOUNT++; }
                if (dotCOUNT == limit) { break; }
                saveLong = i;
            }
            saveLong = saveLong + 2;
            Char[] IPad_cut2 = new Char[saveLong];    //New Char, cut IP address
            for (int i = 0; i < saveLong; i++)
            {
                IPad_cut2[i] = IPad_cut[i];
            }
            String adresoPradzia = new String(IPad_cut2);// String, cut IP Address 123.213.123.
            String NewIP;
            for (int i = 0; i < 256; i++)
            {
                     IPAddress ip = IPAddress.Parse(NewIP);  //New IP 123.123.123.+1, 123.123.123+2.....

    This code work, but he is long and I now, is short function, ant that function do same like this my long code.
    Maybe some now? :]
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    Couldn't you just do this:
    [code=c#]
    for(int i=1; i<256; i++)
    {
    string ipaddy="123.123 .123."+i.ToStri ng();
    IPAddress ip = IPAddress.Parse (ipaddy);
    //do whatever you want with the ip addy.
    }
    [/code]

    Comment

    Working...