Click here to Skip to main content
16,016,759 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello friends,

i am creating an application for my college in c# that listout all the ip-address of computers connected on workgroup "MCA".

how can i do that in c# ? is there any library available ??

and after clicking on particular ip-address(or pc-name) how can i
get the hardware details of that computer
on the Server ??

thank you in advance.

-ripal
Posted

1 solution

using System;
using System.Runtime.InteropServices;
using System.Net;
using System.Net.Sockets;
namespace TcNetSendPlus
{
    /// <summary>
    /// Summary description for ClsNetApiSend.
    /// </summary>
    public class ClsNetApiSend
    {
        // External api declaration
        [DllImport("NetApi32")] public static extern int
            NetMessageBufferSend(uint ServerName,uint MsgName, uint FromName,uint Buffer,ulong BufferLen);
        // Local computer name
        private string ThisComputer;
        public string lstrError;
        public ClsNetApiSend()
        {
            // Store local computer name for further processes
            ThisComputer = Dns.GetHostName();
        }
        // Converting the address of an string variable to integer format
        unsafe public static uint GetAddress(string variable)
        {
            // stores the address of string variable
            uint ptrptr;
            // first convert it to a character pointer
            fixed(char* ptr = variable)
            {ptrptr = (uint) ptr;} // and then cast it to an integer
            return ptrptr; // return converted value
        }
        public bool Send(string ServerName, string Message )
        {
            // holds the length of message
            ulong LenMsg;
            // holds send function return status
            int Status;
            // holds the addresses of local computer name, destination computer name
            // and message that is to be sent
            uint ThisPtr, DestPtr, MsgPtr;
            // holds the name of the destination computer, in case of passing
            // the ip address of the destination computer instead of name
            string newServerName = "";
            try
            {
                IPHostEntry ipEntry = new IPHostEntry();
                // Because NetApi functions require parameters in unicode
                // so we need to multiply by 2 the calculated length of the message
                // to get the correct length of the message. The Length member of
                // string class holds the number of the charcters in the string only
                // but unicode charcters are represented by 2 bytes, one for ascii
                // value and the other contains null value.
                LenMsg = (ulong) Message.Length * 2;
                ThisPtr = GetAddress(ThisComputer);
                MsgPtr = GetAddress(Message);
                ipEntry = Dns.Resolve(ServerName);
                newServerName = ipEntry.HostName;
                DestPtr = GetAddress(newServerName);
            }
            catch (System.Exception e)
            {
                this.lstrError = e.Message;
                return false;
            }
            // NetApi32 api function call for message sending
            Status = NetMessageBufferSend(ThisPtr,DestPtr,ThisPtr,MsgPtr,LenMsg);
            // if the returned value is 0 then there is no error
            // otherwise the return value holds the error code.
            if( Status > 0 )
                return false;
            else
                return true;
        }
    }
}


http://www.codeproject.com/KB/applications/NetSendPlus.aspx[^]
 
Share this answer
 
v3
Comments
v4u.ripal 10-Mar-11 0:37am    
many many thanks for replying but
the code and link that u posted here is not my requirenment.
you don't get me what i need.

i want this type of strategy
1) listout all the computer available on workgroup "MCA"
2) on click of particular computer name OR IP address, it will display all the hardware details of that computer.

i don't want to broadcast message for communication between people.

please help me.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900