{"id":4,"date":"2012-10-02T10:28:23","date_gmt":"2012-10-02T08:28:23","guid":{"rendered":"http:\/\/wordpress.igua.es\/?p=4"},"modified":"2012-10-04T17:20:33","modified_gmt":"2012-10-04T15:20:33","slug":"obtener-el-hostname-y-el-dominio-en-net","status":"publish","type":"post","link":"https:\/\/wordpress.igua.es\/index.php\/2012\/10\/02\/obtener-el-hostname-y-el-dominio-en-net\/","title":{"rendered":"Obtener el hostname y el dominio en .NET"},"content":{"rendered":"<p>Obtener el hostname y el dominio usando el lenguaje .NET y m\u00e1s concretamente C# es sencillo, no requiere de funciones complejas ni nada por el estilo.<\/p>\n<p><strong>Obtener el hostname:<\/strong><\/p>\n<p>El hostname se puede obtener con tan solo una linea, \u00abSystem.Environment.MachineName\u00bb nos devolver\u00e1 el nombre de la m\u00e1quina donde se ejecuta.<\/p>\n<p><strong>Obtener el dominio o el grupo de trabajo:<\/strong><\/p>\n<p>Antes de nada debemos comprobar que nuestro proyecto tiene agregadas las referencias a System.Management, en caso negativo tenemos que agregarlas. Una vez que ya tengamos las referencias bien metidas hacemos lo siguiente:<\/p>\n<pre class=\"brush: csharp; title: C\u00f3digo:; notranslate\" title=\"C\u00f3digo:\">\nSystem.Management.SelectQuery query = new System.Management.SelectQuery(&quot;Win32_ComputerSystem&quot;);\nSystem.Management.ManagementObjectSearcher searcher = new System.Management.ManagementObjectSearcher(query);\n foreach (System.Management.ManagementObject mo in searcher.Get())\n {\n  string Dominio = mo&#x5B;&quot;domain&quot;] as string;\n }\n<\/pre>\n<p>En la variable Dominio ya tendremos guardado el valor que actualmente tenga la m\u00e1quina donde se ejecuta.<\/p>\n<!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>Obtener el hostname y el dominio usando el lenguaje .NET y m\u00e1s concretamente C# es sencillo, no requiere de funciones complejas ni nada por el estilo. Obtener el hostname: El hostname se puede obtener con tan solo una linea, \u00abSystem.Environment.MachineName\u00bb &hellip; <a href=\"https:\/\/wordpress.igua.es\/index.php\/2012\/10\/02\/obtener-el-hostname-y-el-dominio-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,6],"class_list":["post-4","post","type-post","status-publish","format-standard","hentry","category-programacion","tag-net","tag-c","tag-windows"],"_links":{"self":[{"href":"https:\/\/wordpress.igua.es\/index.php\/wp-json\/wp\/v2\/posts\/4","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=4"}],"version-history":[{"count":10,"href":"https:\/\/wordpress.igua.es\/index.php\/wp-json\/wp\/v2\/posts\/4\/revisions"}],"predecessor-version":[{"id":17,"href":"https:\/\/wordpress.igua.es\/index.php\/wp-json\/wp\/v2\/posts\/4\/revisions\/17"}],"wp:attachment":[{"href":"https:\/\/wordpress.igua.es\/index.php\/wp-json\/wp\/v2\/media?parent=4"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wordpress.igua.es\/index.php\/wp-json\/wp\/v2\/categories?post=4"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wordpress.igua.es\/index.php\/wp-json\/wp\/v2\/tags?post=4"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}