Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8007197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:44:56+00:00 2026-06-04T17:44:56+00:00

first question here! I have written and borrowed code to form a IP Address

  • 0

first question here!

I have written and borrowed code to form a IP Address and MAC address finder console application. It send Asynchrous Ping request, and for every IP Address it finds it does and ARP request to find the MAC address.

How can I configure this to work with a different submask than /24 (255.255.255.0) to find IP Address’s?

This is NOT for a botnet. It is for my friend who is a network technician.

using System;
using System.Diagnostics;
using System.Net;
using System.Net.NetworkInformation;
using System.Net.Sockets;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;

namespace FindIpAndMacPro
{
    internal class Program
    {
        private static CountdownEvent _countdown;
        private static int _upCount;
        private static readonly object LockObj = new object();

        private static void Main()
        {
            _countdown = new CountdownEvent(1);
            var sw = new Stopwatch();
            sw.Start();
            Console.Write("Skriv in IP-Adress");
            string ipBase = Console.ReadLine();

            for (int i = 0; i < 255; i++)
            {
                string ip = ipBase + "." + i;
                //Console.WriteLine(ip);
                var p = new Ping();
                p.PingCompleted += PPingCompleted;
                _countdown.AddCount();
                p.SendAsync(ip, 100, ip);
            }

            _countdown.Signal();
            _countdown.Wait();
            sw.Stop();
            new TimeSpan(sw.ElapsedTicks);
            Console.WriteLine("Took {0} milliseconds. {1} hosts active.", sw.ElapsedMilliseconds, _upCount);
            Console.WriteLine("External IP (whatismyip.com): {0}", GetExternalIp());
            Console.ReadLine();
        }

        private static void PPingCompleted (object sender, PingCompletedEventArgs e)
        {
            var ip = (string) e.UserState;
            if (e.Reply != null && e.Reply.Status == IPStatus.Success)
            {

                {
                    string name;
                    string macAddress = "";

                    try
                    {
                        IPHostEntry hostEntry = Dns.GetHostEntry(ip);
                        name = hostEntry.HostName;
                        macAddress = GetMac(ip);
                    }
                    catch (SocketException)
                    {
                        name = "?";
                    }
                    Console.WriteLine("{0} | {1} ({2}) is up: ({3} ms)", ip, macAddress, name, e.Reply.RoundtripTime);
                }
                lock (LockObj)
                {
                    _upCount++;
                }
            }
            else if (e.Reply == null)
            {
                Console.WriteLine("Pinging {0} failed. (Null Reply object?)", ip);
            }
            _countdown.Signal();
        }

        [DllImport ("iphlpapi.dll")]
        public static extern int SendARP (int destIp, int srcIp, [Out] byte[] pMacAddr, ref int phyAddrLen);

        private static string GetMac (String ip)
        {
            IPAddress addr = IPAddress.Parse(ip);
            var mac = new byte[6];
            int len = mac.Length;
            SendARP(ConvertIpToInt32(addr), 0, mac, ref len);
            return BitConverter.ToString(mac, 0, len);
        }

        private static Int32 ConvertIpToInt32 (IPAddress apAddress)
        {
            byte[] bytes = apAddress.GetAddressBytes();
            return BitConverter.ToInt32(bytes, 0);
        }

        private static string GetExternalIp()
        {
            const string whatIsMyIp = "http://automation.whatismyip.com/n09230945.asp";
            var wc = new WebClient();
            var utf8 = new UTF8Encoding();
            string requestHtml = "";
            try
            {
                requestHtml = utf8.GetString(wc.DownloadData(whatIsMyIp));
            }
            catch (WebException we)
            {
                Console.WriteLine(we.ToString());
            }

            return requestHtml;
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T17:44:58+00:00Added an answer on June 4, 2026 at 5:44 pm

    first of all you had to calculate the network from subnetmask.if your subnetmask is 255.255.248.0 then you can easly calculate by subtracting the subnetmask from 255. example: 192.168.32.0/21 (255.255.248.0)

     255.255.255.255
    -255.255.248.0
     ---------------
      0 . 0 . 7 . 255
    

    the network range is from 192.168.32.0 to 192.168.39.255 (32 + 7)
    every 0 is your ipBase here 192.168. the rest is done with for loops. so for all possible networks you need up to 4 for loops. one for every octet of an ip address.
    maybe you can use an existing class for calculating subnets but i don’t know such a class

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My first question here :) I am working with an application written in C++
I have a quick question here. I know that the cakePHP find('first') function returns
Hi this is the first time I am asking a question here. I have
this is my first question.. so, here we go. i have a site, 100%
Sorry, this's my first time to ask a question here. So, I don't have
this is my first time posting here, I have a question which I have
First question here. I'm trying Javascript objects. Here's my code: function main(){ document.onkeydown =
i have written a small piece of code. This code first blocks the {SIGSEGV},
First of all, I do not have any code written yet, I am only
lets get straight to my problem, the code I have written here does not

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.