أرشيف انكور
(نسخة قابلة للطباعة من الموضوع)
https://archive.iinkor.com/t1423
أنقر هنا لمشاهدة الموضوع بهيئته الأصلية

الحصول على اسم مضيف الجهاز أو المضيف المحلي في الجافا
Admin 12-02-2021 03:25 مساءً
بسم الله الرحمن الرحيم

لمشاهدة الروابط يلزمك التسجيل
يوضح المثال أدناه كيفية الحصول على اسم مضيف localhost. باستخدام فئة InetAddress يمكنك الحصول على اسم المضيف للجهاز الحالي. حيث يوفر InetAddress.getLocalHost () كائن InetAddress ، ومن خلال استدعاء أسلوب getHostName () عليه ، سيوفر لك اسم المضيف.

CODE
import java.net.InetAddress;<br />
import java.net.UnknownHostException;<br />
&nbsp;<br />
public class MyLocalHostName {<br />
&nbsp; &nbsp; public static void main(String a[]){<br />
&nbsp; &nbsp; &nbsp; &nbsp; try {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; InetAddress myHost = InetAddress.getLocalHost();<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println(myHost.getHostName());<br />
&nbsp; &nbsp; &nbsp; &nbsp; } catch (UnknownHostException ex) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ex.printStackTrace();<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; }<br />
}<br />
<br />


بالتوفيق للجميع
والسلام ختام
أرشيف انكور

Copyright © 2009-2025 PBBoard® Solutions. All Rights Reserved