Click here to Skip to main content
15,892,643 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
GeneralRe: VERSIONING Pin
Mark Churchill16-Aug-07 16:54
Mark Churchill16-Aug-07 16:54 
Question.NET Framework versions Pin
'Drew8-Aug-07 6:22
'Drew8-Aug-07 6:22 
AnswerRe: .NET Framework versions Pin
Gourav_pn8-Aug-07 6:32
Gourav_pn8-Aug-07 6:32 
AnswerRe: .NET Framework versions Pin
originSH8-Aug-07 22:07
originSH8-Aug-07 22:07 
GeneralRe: .NET Framework versions Pin
Vasudevan Deepak Kumar14-Aug-07 4:43
Vasudevan Deepak Kumar14-Aug-07 4:43 
QuestionGetting a computer name from the IP address(C#) Pin
WvdW8-Aug-07 4:06
WvdW8-Aug-07 4:06 
AnswerRe: Getting a computer name from the IP address(C#) Pin
pbraun8-Aug-07 9:58
pbraun8-Aug-07 9:58 
AnswerRe: Getting a computer name from the IP address(C#) Pin
Reto Ravasio10-Aug-07 9:55
Reto Ravasio10-Aug-07 9:55 
the longer answer is YesSmile | :) .

I had once a similar problem an found that NetWkstaGetInfo[^] worked quite well. You can provide the IP address as input and get the (BIOS-)name of the machine (and other stuff) back.


If I remember correctly I've had had some security issues with workstation configurations (domain worked well). The following c# 2.0 code is all that's needed.


C#
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Globalization;
using NetScan.Contract;
using System.Diagnostics;

namespace NetScan.Service
{
   static class NetBios
   {
      #region public

      public class Info
      {
         private Info()
         {
         }
         internal Info(PlatformId platformId, Version version, string computerName, string lanGroup)
         {
            this.PlatformId = platformId;
            this.Version = version;
            this.ComputerName = computerName;
            this.LanGroup = lanGroup;
         }
         public readonly PlatformId PlatformId;
         public readonly Version Version;
         public readonly string ComputerName;
         public readonly string LanGroup;

         public string Comment;
         public ServerType ServerType;

         public override string ToString()
         {
            return string.Format(CultureInfo.CurrentCulture, "{0} - {1} - {2}", Version, ComputerName, LanGroup);
         }
      }

      public static Info GetInfo(string serverName)
      {
         Info retVal = null;
         System.IntPtr x;
         uint lret = NativeMethods.NetWkstaGetInfo(serverName, 100, out x);
         if (lret != 0 || x == System.IntPtr.Zero)
         {
            return null;
         }
         NativeMethods.WKSTA_INFO_100 wi = (NativeMethods.WKSTA_INFO_100)Marshal.PtrToStructure(x, typeof(NativeMethods.WKSTA_INFO_100));
         retVal = new Info((PlatformId)wi.wki100_platform_id, new Version(wi.wki100_ver_major, wi.wki100_ver_minor), Marshal.PtrToStringUni(wi.wki100_computername), Marshal.PtrToStringUni(wi.wki100_langroup));
         NativeMethods.NetApiBufferFree(x);

         lret = NativeMethods.NetServerGetInfo(serverName, 101, out x);
         if (lret == 0 && x != System.IntPtr.Zero)
         {
            NativeMethods.SERVER_INFO_101 si = (NativeMethods.SERVER_INFO_101)Marshal.PtrToStructure(x, typeof(NativeMethods.SERVER_INFO_101));
            retVal.Comment = Marshal.PtrToStringUni(si.sv101_comment);
            retVal.ServerType = (ServerType)si.sv101_type;
            NativeMethods.NetApiBufferFree(x);
         }

         return retVal;
      }

      #endregion

      private static class NativeMethods
      {
         internal enum PlatformId : int
         {
            PLATFORM_ID_DOS = 300,
            PLATFORM_ID_OS2 = 400,
            PLATFORM_ID_NT = 500,
            PLATFORM_ID_OSF = 600,
            PLATFORM_ID_VMS = 700,
         }

         [Flags]
         internal enum SVType : uint
         {
            SV_TYPE_WORKSTATION = 0x00000001,
            SV_TYPE_SERVER = 0x00000002,
            SV_TYPE_SQLSERVER = 0x00000004,
            SV_TYPE_DOMAIN_CTRL = 0x00000008,
            SV_TYPE_DOMAIN_BAKCTRL = 0x00000010,
            SV_TYPE_TIME_SOURCE = 0x00000020,
            SV_TYPE_AFP = 0x00000040,
            SV_TYPE_NOVELL = 0x00000080,
            SV_TYPE_DOMAIN_MEMBER = 0x00000100,
            SV_TYPE_PRINTQ_SERVER = 0x00000200,
            SV_TYPE_DIALIN_SERVER = 0x00000400,
            SV_TYPE_XENIX_SERVER = 0x00000800,
            SV_TYPE_SERVER_UNIX = SV_TYPE_XENIX_SERVER,
            SV_TYPE_NT = 0x00001000,
            SV_TYPE_WFW = 0x00002000,
            SV_TYPE_SERVER_MFPN = 0x00004000,
            SV_TYPE_SERVER_NT = 0x00008000,
            SV_TYPE_POTENTIAL_BROWSER = 0x00010000,
            SV_TYPE_BACKUP_BROWSER = 0x00020000,
            SV_TYPE_MASTER_BROWSER = 0x00040000,
            SV_TYPE_DOMAIN_MASTER = 0x00080000,
            SV_TYPE_SERVER_OSF = 0x00100000,
            SV_TYPE_SERVER_VMS = 0x00200000,
            SV_TYPE_WINDOWS = 0x00400000, // Windows95 and above
            SV_TYPE_DFS = 0x00800000, // Root of a DFS tree
            SV_TYPE_CLUSTER_NT = 0x01000000, // NT Cluster
            SV_TYPE_TERMINALSERVER = 0x02000000, // Terminal Server(Hydra)
            SV_TYPE_CLUSTER_VS_NT = 0x04000000, // NT Cluster Virtual Server Name
            SV_TYPE_DCE = 0x10000000, // IBM DSS (Directory and Security Services) or equivalent
            SV_TYPE_ALTERNATE_XPORT = 0x20000000, // return list for alternate transport
            SV_TYPE_LOCAL_LIST_ONLY = 0x40000000, // Return local list only
            SV_TYPE_DOMAIN_ENUM = 0x80000000,
            SV_TYPE_ALL = 0xFFFFFFFF, /* handy for NetServerEnum2 */
         }


         [StructLayout(LayoutKind.Sequential)]
         internal struct WKSTA_INFO_100
         {
            public PlatformId wki100_platform_id;
            public IntPtr wki100_computername;
            public IntPtr wki100_langroup;
            public int wki100_ver_major;
            public int wki100_ver_minor;
         }

         [StructLayout(LayoutKind.Sequential)]
         public struct WKSTA_INFO_101
         {
            public PlatformId wki101_platform_id;
            public IntPtr wki101_computername;
            public IntPtr wki101_langroup;
            public int wki101_ver_major;
            public int wki101_ver_minor;
            public IntPtr wki101_lanroot;
         }

         [StructLayout(LayoutKind.Sequential)]
         public struct SERVER_INFO_100
         {
            public PlatformId sv100_platform_id;
            public IntPtr sv100_name;
         }

         [StructLayout(LayoutKind.Sequential)]
         public struct SERVER_INFO_101
         {
            public PlatformId sv101_platform_id;
            public IntPtr sv101_name;
            public uint sv101_version_major;
            public uint sv101_version_minor;
            public SVType sv101_type;
            public IntPtr sv101_comment;
         }

         [DllImport("netapi32.dll", CharSet = CharSet.Auto, SetLastError = true)]
         internal static extern int NetApiBufferFree(System.IntPtr pBuffer);

         [DllImport("netapi32.dll", CharSet = CharSet.Auto, SetLastError = true)]
         internal static extern uint NetServerGetInfo([MarshalAs(UnmanagedType.LPWStr)] string serverName, int level, out IntPtr Buffer);

         [DllImport("netapi32.dll", CharSet = CharSet.Auto, SetLastError = true)]
         internal static extern uint NetWkstaGetInfo([MarshalAs(UnmanagedType.LPWStr)] string serverName, int level, out IntPtr Buffer);
      }

   }
}

GeneralRe: Getting a computer name from the IP address(C#) Pin
Reto Ravasio10-Aug-07 10:07
Reto Ravasio10-Aug-07 10:07 
QuestionSwitching from http to https??????????/ Pin
Nithin Krishna7-Aug-07 2:27
Nithin Krishna7-Aug-07 2:27 
AnswerRe: Switching from http to https??????????/ Pin
Luc Pattyn7-Aug-07 2:31
sitebuilderLuc Pattyn7-Aug-07 2:31 
AnswerRe: Switching from http to https??????????/ Pin
Vasudevan Deepak Kumar14-Aug-07 4:44
Vasudevan Deepak Kumar14-Aug-07 4:44 
QuestionFramework usage statistics Pin
khaos_dj6-Aug-07 22:08
khaos_dj6-Aug-07 22:08 
QuestionRe: Framework usage statistics Pin
just.jimmy8-Aug-07 14:41
just.jimmy8-Aug-07 14:41 
AnswerRe: Framework usage statistics Pin
Pete O'Hanlon8-Aug-07 21:47
mvePete O'Hanlon8-Aug-07 21:47 
GeneralRe: Framework usage statistics Pin
just.jimmy8-Aug-07 22:03
just.jimmy8-Aug-07 22:03 
AnswerRe: Framework usage statistics Pin
Kevin McFarlane10-Aug-07 2:09
Kevin McFarlane10-Aug-07 2:09 
QuestionASPX files unaccessible now and then . Pin
Anmol.Gupta6-Aug-07 21:26
Anmol.Gupta6-Aug-07 21:26 
AnswerRe: ASPX files unaccessible now and then . Pin
Anmol.Gupta13-Aug-07 3:02
Anmol.Gupta13-Aug-07 3:02 
Question.Net framework compatibility Pin
pavya_Cool6-Aug-07 20:44
pavya_Cool6-Aug-07 20:44 
AnswerRe: .Net framework compatibility Pin
Pete O'Hanlon6-Aug-07 21:50
mvePete O'Hanlon6-Aug-07 21:50 
Questionredirect native dll printf output within .NET exe to a file Pin
chervu6-Aug-07 4:46
chervu6-Aug-07 4:46 
Questionproblem i displaying images Pin
ooooooooppppppss5-Aug-07 20:30
ooooooooppppppss5-Aug-07 20:30 
AnswerRe: problem i displaying images Pin
ne0h5-Aug-07 21:23
ne0h5-Aug-07 21:23 
JokeRe: problem i displaying images Pin
Luc Pattyn7-Aug-07 2:34
sitebuilderLuc Pattyn7-Aug-07 2:34 

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

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.