Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I have an USB Ethernet adapter at my PC (with a static IP) and only one ethernet device connected. The device is in DHCP mode.
Now I must give them an IP address (always the same) without using an external DHCP server.
I would like to do it with very few lines.
Does anybody have a solution for that?

Thanks in advance.

What I have tried:

I tried some C# snippets, but without success.
Posted
Updated 25-Oct-23 8:48am
v2
Comments
Dave Kreskowiak 16-Oct-23 10:01am    
Why are you trying to dole out IP addresses from your own code? You would be writing your own DHCP server to do that, even if it's for a single device connected to your "network".

Just configure the device itself to use a static IP and set the address there. You do it once and it stays at that address until you change it again.
roywO 16-Oct-23 10:07am    
Hi Dave,
I can't use static IP, because I will connect many devices that comes in DHCP mode one after another.
When the device is connected and get the fix IP I will set some settings in this device, disconnect and connect the next device .
Dave Kreskowiak 16-Oct-23 13:24pm    
You replied to your own post, not me, so I never got a notification you replied.

Your situation makes no sense at all. Once you disconnect the device from your "network", that devices IP address is no longer valid, so the IP you're setting doesn't mean anything at that point.

Are you really just trying to set a static IP on each device in an effort to configure that device? Like you're setting up each device for later deployment in a different environment?
0x01AA 16-Oct-23 10:42am    
Implement a minimal DHCP Server, there are a lot of examples available.
[no name] 16-Oct-23 11:26am    
Buy a "hub" or something for a few dollars.

1 solution

Normally, you would set a "IP address reservation" in a DHCP server to set static IP's on a device that is requesting them via DHCP. This gives you the ability to manage the reserved list in a centralized place instead of having to go to every device to reconfigure each one for a new address/network.

You cannot use DHCP to permanently set an IP address on a device once, and expect that device to use that address the next time it's powered up. DHCP will kick in again and make another request for an address, and if it doesn't get one, it cannot be expected use the same address that was previously assigned.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900