{"id":26,"date":"2012-10-08T21:20:23","date_gmt":"2012-10-08T19:20:23","guid":{"rendered":"http:\/\/wordpress.igua.es\/?p=26"},"modified":"2012-10-08T17:22:05","modified_gmt":"2012-10-08T15:22:05","slug":"como-obtener-el-nombre-del-dominio-de-netbios-de-un-equipo-en-net","status":"publish","type":"post","link":"https:\/\/wordpress.igua.es\/index.php\/2012\/10\/08\/como-obtener-el-nombre-del-dominio-de-netbios-de-un-equipo-en-net\/","title":{"rendered":"Como obtener el nombre del dominio de NetBios de un equipo en .NET"},"content":{"rendered":"<p>Para poder obtener informaci\u00f3n de netbios nos vamos a tener que meter en c\u00f3digo de bastante bajo nivel por lo que para poder usarlo en .NET vamos a recurrir a las pinvoke<\/p>\n<pre class=\"brush: csharp; title: C\u00f3digo:; notranslate\" title=\"C\u00f3digo:\">\n    using System.Runtime.InteropServices;\n    using System.ComponentModel;\n\n    public class NetUtil\n    {\n        &#x5B;DllImport(&quot;netapi32.dll&quot;, CharSet = CharSet.Auto)]\n        static extern int NetWkstaGetInfo(string server,\n            int level,\n            out IntPtr info);\n\n        &#x5B;DllImport(&quot;netapi32.dll&quot;)]\n        static extern int NetApiBufferFree(IntPtr pBuf);\n\n        &#x5B;StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]\n        class WKSTA_INFO_100\n        {\n            public int wki100_platform_id;\n            &#x5B;MarshalAs(UnmanagedType.LPWStr)]\n            public string wki100_computername;\n            &#x5B;MarshalAs(UnmanagedType.LPWStr)]\n            public string wki100_langroup;\n            public int wki100_ver_major;\n            public int wki100_ver_minor;\n        }\n\n        public static string GetMachineNetBiosDomain()\n        {\n            IntPtr pBuffer = IntPtr.Zero;\n\n            WKSTA_INFO_100 info;\n            int retval = NetWkstaGetInfo(null, 100, out pBuffer);\n            if (retval != 0)\n                throw new Win32Exception(retval);\n\n            info = (WKSTA_INFO_100)Marshal.PtrToStructure(pBuffer, typeof(WKSTA_INFO_100));\n            string domainName = info.wki100_langroup;\n            NetApiBufferFree(pBuffer);\n            return domainName;\n        }\n    }\n<\/pre>\n<p>Tras colocar el c\u00f3digo anterior en una clase de nuestro proyecto ya podremos obtener el dominio usando:<\/p>\n<pre class=\"brush: csharp; title: C\u00f3digo:; notranslate\" title=\"C\u00f3digo:\">\n   NetUtil.GetMachineNetBiosDomain()\n<\/pre>\n<!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>Para poder obtener informaci\u00f3n de netbios nos vamos a tener que meter en c\u00f3digo de bastante bajo nivel por lo que para poder usarlo en .NET vamos a recurrir a las pinvoke using System.Runtime.InteropServices; using System.ComponentModel; public class NetUtil { &hellip; <a href=\"https:\/\/wordpress.igua.es\/index.php\/2012\/10\/08\/como-obtener-el-nombre-del-dominio-de-netbios-de-un-equipo-en-net\/\">Sigue leyendo <span class=\"meta-nav\">&rarr;<\/span><\/a><!-- AddThis Advanced Settings generic via filter on get_the_excerpt --><!-- AddThis Share Buttons generic via filter on get_the_excerpt --><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[3,4],"class_list":["post-26","post","type-post","status-publish","format-standard","hentry","category-programacion","tag-net","tag-c"],"_links":{"self":[{"href":"https:\/\/wordpress.igua.es\/index.php\/wp-json\/wp\/v2\/posts\/26","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.igua.es\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wordpress.igua.es\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wordpress.igua.es\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wordpress.igua.es\/index.php\/wp-json\/wp\/v2\/comments?post=26"}],"version-history":[{"count":11,"href":"https:\/\/wordpress.igua.es\/index.php\/wp-json\/wp\/v2\/posts\/26\/revisions"}],"predecessor-version":[{"id":37,"href":"https:\/\/wordpress.igua.es\/index.php\/wp-json\/wp\/v2\/posts\/26\/revisions\/37"}],"wp:attachment":[{"href":"https:\/\/wordpress.igua.es\/index.php\/wp-json\/wp\/v2\/media?parent=26"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wordpress.igua.es\/index.php\/wp-json\/wp\/v2\/categories?post=26"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wordpress.igua.es\/index.php\/wp-json\/wp\/v2\/tags?post=26"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}