Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 150,073 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,777 people online right now. Registration is fast and FREE... Join Now!




Help : Modify IP Address

 
Reply to this topicStart new topic

Help : Modify IP Address, Help : Modify IP Address

smyle22
6 Jun, 2008 - 02:32 AM
Post #1

New D.I.C Head
*

Joined: 6 Jun, 2008
Posts: 5

Good day experts..
Pls help me with my problem.. i need a code that will modify IP Address..
Im working with a txtbox where user will fill with an IP address then when she/he click apply it will automatically change the IP address on the registry and on LAN.. thanks alot!
User is offlineProfile CardPM
+Quote Post

ferrari12508
RE: Help : Modify IP Address
6 Jun, 2008 - 02:43 AM
Post #2

D.I.C Lover
Group Icon

Joined: 2 Nov, 2007
Posts: 1,112



Thanked: 2 times
Dream Kudos: 150
My Contributions
Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code for homework assignments. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well.

User is offlineProfile CardPM
+Quote Post

smyle22
RE: Help : Modify IP Address
6 Jun, 2008 - 03:06 AM
Post #3

New D.I.C Head
*

Joined: 6 Jun, 2008
Posts: 5

QUOTE(ferrari12508 @ 6 Jun, 2008 - 03:43 AM) *

Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code for homework assignments. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well.


i have already posted one.. "Modify system date and time"..
thanks for reminding me.. pls someone help me!!!
User is offlineProfile CardPM
+Quote Post

born2c0de
RE: Help : Modify IP Address
6 Jun, 2008 - 11:46 PM
Post #4

printf("I'm a %XR",195936478);
Group Icon

Joined: 26 Nov, 2004
Posts: 4,032



Thanked: 38 times
Dream Kudos: 2800
Expert In: 80x86 Assembly, C/C++, VB6, VB.NET, C#, J2SE, Win32 API, Reversing

My Contributions
Unfortunately there is no base class to do this in .NET nor is there an API function to do this directly.
You will have to manually edit th entries in the Registry.

You'll need to follow this procedure:
  • Iterate through all the sub-keys in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards
  • Store the various ServiceNames in an Array. These ServiceNames are the names of the available network cards on the current machine.
  • The next thing you should do is check which network card's IP address you want to change. Let its service name be X
  • Visit the following Registry Key : HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\X\TcpIp
  • Modify whichever field you need to change. You will need to modify one or more of these fields:
    • DefaultGateway
    • DhcpDefaultGateway
    • DhcpIPAddress
    • DhcpServer
    • DhcpSubnetMask
    • IPAddress
    • ..etc..
  • You're done!!!

I've written this as detailed as possible.
You should now be able to code this procedure very easily in VB.NET.
smile.gif

One more thing:
To modify the IPAddress field, you will need to store the IP Address as a set of Bytes (terminated by two nulls) and not as a string.

Use this to change the IP-Address Field:
vb
 <regObject>.SetValue("IPAddress", Encoding.ASCII.GetBytes("127.0.0.1\0\0"))

User is online!Profile CardPM
+Quote Post

RodgerB
RE: Help : Modify IP Address
7 Jun, 2008 - 01:50 AM
Post #5

D.I.C Lover
Group Icon

Joined: 21 Sep, 2007
Posts: 2,166



Thanked: 17 times
Dream Kudos: 2200
Expert In: Dot Net Technologies

My Contributions
I formed a snippet based on some C# code I saw on how to do this through WMI. You can view it here (click).
User is online!Profile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 11:08PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month