منتدى فيجوال بيسك لكل العرب | منتدى المبرمجين العرب

نسخة كاملة : (تم الحل) طلب كود تغيير ip الجهاز
أنت حالياً تتصفح نسخة خفيفة من المنتدى . مشاهدة نسخة كاملة مع جميع الأشكال الجمالية .
السلام عليكم ورحمة الله وبركاته
أخواني
أريد كود يقوم بإضافة
IP في بروتوكول TCP/IPv4

حيث ان بدلا ما أدخل في محولات الأتصال واروح الخصائص وبعدين ادخل في خيارات TCP/IPv4 واضيف IP
خلاص من خلال هذا الكود أضيف IP إللي أبيه

وشكرا
مرفق مثال به المطلوب
أخي البرنامج لايعمل Sad

فقط يكتب ping ورقم الإيبي في مربع textbox بشكل مستمر
ولا يغير شيء

وجربت أفتحه كمسؤول نفس الحال
بسم الله الرحمن الرحيم
استعمل الاجراء التالي

1) Project > Add Reference > System.Management option in the list.


2) Add 'Imports System.Management' (without the quotation) to the top of your code.

PHP كود :
''' <summary>
''' 
Sets the IP address of the local machine.
''' </summary>
''' 
<param name="IPAddress">The IP address to set the computer to</param>
''' <param name="SubnetMask">The subnet mask to set the computer to</param>
''' 
<param name="Gateway">The gateway to set the computer to</param>
''' <remarks>Adapted from code by Logu Krishnan at
''' 
http://www.codeproject.com/KB/system/cstcpipwmi.aspx
''' Requires a reference to the System.Management namespace</remarks>
Private Sub SetIP(ByVal IPAddress As String, ByVal SubnetMask As String, _
* * * * * * * * * ByVal Gateway As String)




* * Dim managementClass As New ManagementClass("Win32_NetworkAdapterConfiguration")
* * Dim mgObjCollection As ManagementObjectCollection = managementClass.GetInstances()




* * For Each mgObject As ManagementObject In mgObjCollection
* * * * If Not CType(mgObject("IPEnabled"), Boolean) Then Continue For




* * * * Try
* * * * * * Dim objNewIP As ManagementBaseObject = Nothing
* * * * * * Dim objSetIP As ManagementBaseObject = Nothing
* * * * * * Dim objNewGate As ManagementBaseObject = Nothing




* * * * * * objNewIP = mgObject.GetMethodParameters("EnableStatic")
* * * * * * objNewGate = mgObject.GetMethodParameters("SetGateways")




* * * * * * ' 
Set the default gateway (decided to declare and initialise
* * * * * * ' variables rather than attempting to initialize the array
* * * * * * ' 
while communicating with the WMI.
* * * * * * 
Dim tmpStrArray() As String = {Gateway}




* * * * * * 
objNewGate("DefaultIPGateway") = tmpStrArray
* * * * * * Dim tmpIntArray() As Integer = {1}
* * * * * * 
objNewGate("GatewayCostMetric") = tmpIntArray




* * * * * * ' Set the IP address and subnet.
* * * * * * tmpStrArray(0) = IPAddress
* * * * * * objNewIP("IPAddress") = tmpStrArray
* * * * * * tmpStrArray(0) = SubnetMask
* * * * * * objNewIP("SubnetMask") = tmpStrArray




* * * * * * objSetIP = mgObject.InvokeMethod("EnableStatic", objNewIP, Nothing)
* * * * * * objSetIP = mgObject.InvokeMethod("SetGateways", objNewGate, Nothing)
* * * * Catch ex As Exception
* * * * * * MessageBox.Show("An error occured: " + ex.Message)
* * * * End Try
* * Next
End Sub 


كود الاستدعاء
PHP كود :
' Example Usage
SetIP("192.168.1.230", "255.255.255.0", "192.168.1.51") 
ارفقت لك الكود في ملف نصي لان بعض الكلمات ممنوعة بالمنتدى
فتظهر لك (****)

تحياتي لك
ابو سامي

اشتغل كود الأخ M.Sami.AK

* ملاحظة يجب تشغيل البرنامج كمسؤول

هنااا
تسلموا على المساعدة جزاكم الله خير

~ تم الحل ~
تم ايجاد الحل المناسب