Click here to Skip to main content
Click here to Skip to main content

Network Scanner App

By , 18 Oct 2012
 

Please note

This article is an entry in our AppInnovation Contest. Articles in this sub-section are not required to be full articles so care should be taken when voting.

Introduction

My app provides a mechanism for supplying a list of all PC names in the local network. It scans the software installed with their product keys in each machine from its registry and displays it against the Machine. It will also scans hardware details such as Make, Model, Clock Speed, Hard Disk size, RAM and all. This app is very useful for the infrastructure admins to monitor and maintain the list of sotware and its licenses along with the hardware details.

Background

This application is very good tool for the administrator to keep track of all the PC related information.Whenever user installs new software without giving information to admin,this app send a an alert mail to admin against the installed software.All installed and uninstalled software and any system upgradation details can be tracked.

This app makes use of the following code

  1. // Netapi32.dll : NetServerEnum, The NetServerEnum function lists all servers of all the specified type that are visible in a domain.
    [DllImport("Netapi32", CharSet = CharSet.Auto, SetLastError = true),
    
    SuppressUnmanagedCodeSecurityAttribute]
    
    public static extern int NetServerEnum(
    
    string ServerNane, // must be null
    
    int dwLevel,
    
    ref IntPtr pBuf,
    
    int dwPrefMaxLen,
    
    out int dwEntriesRead,
    
    out int dwTotalEntries,
    
    int dwServerType,
    
    string domain, // null for login domain
    
    out int dwResumeHandle
    
    );
     
    
  2. //Netapi32.dll : The NetApiBufferFree function frees the memory that the NetApiBufferAllocate function allocates.Call NetApiBufferFree to free the memory that other network management functions return.
    
    [DllImport("Netapi32", SetLastError = true),
    
    SuppressUnmanagedCodeSecurityAttribute]
    
    public static extern int NetApiBufferFree(
    
    IntPtr pBuf);
    
    //create a _SERVER_INFO_100 STRUCTURE
    
    [StructLayout(LayoutKind.Sequential)]
    
    public struct _SERVER_INFO_100
    
    {
    
    internal int sv100_platform_id;
    
    [MarshalAs(UnmanagedType.LPWStr)]
    
    internal string sv100_name;
    
    }
  3. //Define an Arraylist 
    
    ArrayList networkComputers = new ArrayList();
  4. const int MAX_PREFERRED_LENGTH = -1;
    
    int SV_TYPE_WORKSTATION = 1;
    
    int SV_TYPE_SERVER = 2;
    
    // int SV_TYPE_PRINTER = 1;
    
    string strDmn = "domain";
    
    IntPtr buffer = IntPtr.Zero;
    
    IntPtr tmpBuffer = IntPtr.Zero;
    
    int entriesRead = 0;
    
    int totalEntries = 0;
    
    int resHandle = 0;
    
    int sizeofINFO = Marshal.SizeOf(typeof(_SERVER_INFO_100));
    
    try
    
    {
    
    int ret = NetServerEnum(null, 100, ref buffer, MAX_PREFERRED_LENGTH,
    
    out entriesRead,
    
    out totalEntries,SV_TYPE_WORKSTATION | SV_TYPE_SERVER , null, out 
    
    resHandle);
    
    //if the returned with a NERR_Success (C++ term), =0 for C#
    
    if (ret == 0)
    
    {
    
    //loop through all SV_TYPE_WORKSTATION and SV_TYPE_SERVER PC's
    
    for (int i = 0; i < totalEntries; i++)
    
    {
    
    tmpBuffer = new IntPtr((int)buffer + (i * sizeofINFO));
    
    _SERVER_INFO_100 svrInfo = (_SERVER_INFO_100)
    
    Marshal.PtrToStructure(tmpBuffer, typeof(_SERVER_INFO_100));
    
    //add the PC names to the ArrayList
    
    networkComputers.Add(svrInfo.sv100_name);
    
    }
    
    }
    
    }
    
    catch (Exception ex)
    
    {
    
    MessageBox.Show("Problem with acessing network computers in NetworkBrowser " +
    
    "\r\n\r\n\r\n" + ex.Message,
    
    "Error", MessageBoxButtons.OK,
    
    MessageBoxIcon.Error);
    
    return null;
    
    }
    
    finally
    
    {
    
    //The NetApiBufferFree function frees 
    
    //the memory that the NetApiBufferAllocate function allocates
    
    NetApiBufferFree(buffer);
    
    }
     
  5. By using the above code we got the List of PCs connected in local Network.

     6. Gets all the PC names into an Arraylist and for each PC perform the following tasks

  • Ping the PC using ping object
  • if ping status is success then connect to registry of the system and go through the Registry Keys to get the information required.
  • Get the software information such as Display Name,Install location,Install date,Publisher and any License key
  • Get the Hardware details from win32 classes

Points of Interest

I learned many things about Registry information and also Win32 system classes while developing this app.

History

This is the version 1.0 of my app.

License

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

About the Author

Member 7816206
United States United States
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
Generalmy vote 5 for this onemembersrikanth4121 Oct '12 - 1:17 
Generalhow does this work when my ultra book is attached to network in my office?membersrikanth4120 Oct '12 - 23:53 
QuestionHow does this make use of the features of an Ultrabook?adminChris Maunder18 Oct '12 - 15:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web03 | 2.6.130516.1 | Last Updated 18 Oct 2012
Article Copyright 2012 by Member 7816206
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid