Get device IP-address within auto-ip range (169.254.x.y)

kpotmake 1 Reputation point
2021-12-09T08:09:44.23+00:00

I am a PLC programmer (industrial automation) with verry little programming experience in "PC" programming languages such as Python, C, and visual basic. One of my customers has a machine that I have written software for on a simple Eaton PLC (Eaton Easy e4) a while ago. This customer has since built and installed more then 1000 of these machines. My customer wants his field technicians to be able to take a laptop to the machine, connect the laptop to the ethernet port of that PLC, and through simple interface be able to view and edit some of the data in the device. The eaton programming software is too complicated for this since the people who need to use it are not always technicaly skilled.

The PLC's are never part of a network, so there is nothing else connected to them apart from the laptop at that point. These Eaton PLC's have a modbus Server functionality built into them and an ethernet port and that's how I can interface with them over ethernet.

So far I have succeeded in creating a Modbus TCP client in visual basic to read and write the modbus registers. But here's where I'm stuck: These Eaton PLC's are by default set to 'auto-ip'. For my test setup I have checked the IP address of that specific PLC manually and then entered it manually in my application, but this is not what I want for my not so technical customer. I want them to be able to click 'connect' and let visual basic sort it all out (if at all possible...), or any other solution I havent thought of..

As mentioned earlier, these PLC's have auto-ip, so it first tries to get an IP address from a DHCP server, if there is no DHCP server (as is the case with these PLCs, because they aren't connected to a network) they will assign themselves an address somewhere in the range 169.254.x.y. So I can always assume the PLC has an address in that range.

So the question in short: if I have one device (the Eaton PLC) connected to my laptop (directly, no switch, no other devices), and I know it's range to be 169.254.x.y, is there a way to scan for that device and find it's IP address?

Or perhaps any other suggestion that lets me connect my visual basic application (modbus TCP client) to the PLC, such as a DHCP server on the laptop perhaps..? If the laptop can give the PLC an IP address, and I know which address has been given then I know the IP address I need to use in my Modbus TCP client..

Thanks in advance for your suggestions :)

VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,668 questions
Windows DHCP
Windows DHCP
Windows: A family of Microsoft operating systems that run across personal computers, tablets, laptops, phones, internet of things devices, self-contained mixed reality headsets, large collaboration screens, and other devices.DHCP: Dynamic Host Configuration Protocol (DHCP). A communications protocol that lets network administrators manage centrally and automate the assignment of Internet Protocol (IP) addresses in an organization's network.
1,035 questions
0 comments No comments
{count} votes

4 answers

Sort by: Most helpful
  1. Anonymous
    2021-12-09T14:10:48.167+00:00

    Might check the Eaton site for tools. I remember that Rockwell Automation has such a tool. A DHCP server that runs on a desktop OS Its their BootP DHCP EtherNet/IP Tool
    https://compatibility.rockwellautomation.com/Pages/MultiProductFindDownloads.aspx?crumb=112&mode=3&refSoft=1&versions=59657


  2. Dewayne Basnett 1,361 Reputation points
    2021-12-09T14:49:46.237+00:00

    If this, "The PLC's are never part of a network..." is true then these devices should have a fixed IP address.


  3. Dewayne Basnett 1,361 Reputation points
    2021-12-10T16:12:31.977+00:00

    What is the IP subnet mask on the PLC? If the PC you connect to it has DHCP on what is it's IP address and mask? Do you know if the PLC responds to PINGS?


  4. kpotmake 1 Reputation point
    2021-12-13T21:13:33.54+00:00

    Quick update: On the Eaton software tool there is a 'search device' function, which magically finds the IP address of the connected PLC. I tried to figure out how this works by clicking 'search' and then watching the packets with Wireshark. I found out that when I press the 'search' button a UDP broadcast is sent to port 11111 with some data, and then the PLC broadcasts a reply back and that's how eaton finds the IP address.

    I'm trying to replicate this is visual basic now, and so far I've been able to send the broadcast message and on Wireshark I can see the PLC responding with it's address! Hooray!

    Next step is figuring out how to receive the broadcast message from the PLC in visual basic and then I can find the IP address of the PLC.

    Here's how I sent the broadcast message:

    Public Const broadcastPort As Integer = 11111  
    Public Const broadcastAddress As String = "255.255.255.255"  
    Public MyUdpClient As UdpClient  
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click  
        MyUdpClient = New UdpClient(broadcastAddress, broadcastPort)  
        MyUdpClient.EnableBroadcast = True  
    
        Dim data() As Byte = {&H54, &HEA, &HA, &H0, &H0, &H0, &HC0, &HA8, &H1, &HF8, &H67, &H2B, &HFF, &HFF}  
        MyUdpClient.Send(data, data.Length)  
    End Sub  
    

    Wireshark screenshot:
    157302-wireshark.png