TCP connection to MAC address

N

Nicolas Noakes

Hello,

I would like to convert to following process to code. Any advice is
welcome.

I have a hardware device which requires the this procedure to set it's
IP address. First create an static ARP entry for the device's MAC
address and the desired IP address. Then telnet to this IP address on
TCP port 1. This will set the device to temporarily respond to that IP
address. Now you can use HTTP to access the device's web interface and
explicitly set it's IP address.

Basically it looks like creating a TCP connection on port 1, based on
MAC address instead of IP address, then a normal TCP connection on port
80 to do an HTTP POST and set the IP address. The first step may be a
little more involved, since the IP address will have to be included
somewhere.

Please excuse any stupid/misinformed questions - I'm completely new to
C#, and .net for that matter (coming from a VB6 background). I'm
currently using the 2005 Express edition, if that makes any difference.

Regards,
Nicolas
 
C

Chris Shepherd

Nicolas said:
Hello,

I would like to convert to following process to code. Any advice is
welcome.

I have a hardware device which requires the this procedure to set it's
IP address. First create an static ARP entry for the device's MAC
address and the desired IP address. Then telnet to this IP address on
TCP port 1. This will set the device to temporarily respond to that IP
address. Now you can use HTTP to access the device's web interface and
explicitly set it's IP address.

Could you flesh out this process a bit more? I'm confused as to what
you're trying to do. It seems like you want to have some kind of remote
configuration of the host's IP address abilities. What I don't
understand is why creating a static ARP entry is even necessary?

Chris.
 
N

Nicolas Noakes

Chris,

The device a networked logic controller. There is no practical method
available for displaying or otherwise retrieving it's current IP
address. It does not support DHCP - I assume for the same reason that it
cannot tell you what it is using so it would be pointless. The device
may not have an address set (as supplied), or may be on another IP
subnet, or you may just not know its IP address.

Therefore, until you have set the device to an explicit IP address that
you know of, you have no way of communicating with it on the network.

So, here are the instructions from the manufacturer to assign a
temporary IP address to the device (works until the device is rebooted)

1) Create a static ARP entry linking its MAC address to the IP address
you want to give it. e.g.:

arp -s 192.168.1.100 00-02-20-a0-b4-cd

2) Attempt to telnet to this IP address on TCP port 1. Note that this is
expected to fail, it is just a check measure. e.g.:

telnet 192.168.1.100 1

3) Access the device's web interface on the chosen IP address and
explicitly set its IP address, etc. e.g.:

http://192.168.1.100


This process in not difficult or problematic, but it is very manual. I
would like to write a small utility where I can simply enter the MAC
address and desired IP address and click "Set". Both as a useful tool,
and to learn networking from a C# point of view.

Does that help? Thanks for your interest.

Regards,
Nicolas
 
C

Chris Shepherd

Nicolas said:
Chris,

The device a networked logic controller. There is no practical method
available for displaying or otherwise retrieving it's current IP
address. It does not support DHCP - I assume for the same reason that it
cannot tell you what it is using so it would be pointless. The device
may not have an address set (as supplied), or may be on another IP
subnet, or you may just not know its IP address.

Therefore, until you have set the device to an explicit IP address that
you know of, you have no way of communicating with it on the network.

Understood. I'm surprised that they don't support the loopback interface.

[Snippage of instructions]
This process in not difficult or problematic, but it is very manual. I
would like to write a small utility where I can simply enter the MAC
address and desired IP address and click "Set". Both as a useful tool,
and to learn networking from a C# point of view.

Does that help? Thanks for your interest.

Yes it does. Going back to your OP:
Basically it looks like creating a TCP connection on port 1, based on
MAC address instead of IP address, then a normal TCP connection on
port 80 to do an HTTP POST and set the IP address. The first step may
be a little more involved, since the IP address will have to be
included somewhere.

It is not initiating a TCP connection to a MAC address, as those are on
different layers. All it is doing is emulating the loopback address by
setting a default IP, and hitting it on a specific port as a sort of
"secret knock" to unlocking the web interface to the configuration manager.

All you need to really do is:
- Set the static arp table entry to the IP you've chosen.
- Open a TCP connection to that IP on port 1.
- When that fails (you indicated it wasn't expected to work), ignore the
failure and connect to port 80 using a web browser control.

In your code the only thing involving the MAC would be setting the ARP
table entry, and possibly retrieving the MAC address. It is still a very
separate step from the TCP connection to TCP/1 and initiating a web
browser connection.

My suggestion would be to use localhost as the default address
(127.0.0.1) provided it is not already in use on the device. If not,
pick an unused private IP range (10/8, 192.168/16, or 172/8 - IIRC) and
assign it an IP in those ranges.

Chris.
 
N

Nicolas Noakes

Chris said:
Understood. I'm surprised that they don't support the loopback interface.
and

It is not initiating a TCP connection to a MAC address, as those are on
different layers. All it is doing is emulating the loopback address by
setting a default IP, and hitting it on a specific port as a sort of
"secret knock" to unlocking the web interface to the configuration manager.

Perhaps is should have posted in a networking group? I don't follow how
it would help if my device supported the loopback interface. How would
it work it that case? Or rather, how does loopback support in the device
enable me to connect to it from my PC? (These questions are straying
off-topic but I am interested to understand better)
All you need to really do is:
- Set the static arp table entry to the IP you've chosen.
- Open a TCP connection to that IP on port 1.
- When that fails (you indicated it wasn't expected to work), ignore the
failure and connect to port 80 using a web browser control.

Ok, I could basically perform the identical process from code. My only
question is whether there is a method to add the static arp entry from
code, or would I have to do it through a shell command?
My suggestion would be to use localhost as the default address
(127.0.0.1) provided it is not already in use on the device. If not,
pick an unused private IP range (10/8, 192.168/16, or 172/8 - IIRC) and
assign it an IP in those ranges.

Again, my lack of understanding on the loopback interface, but why the
default address of 127.0.0.1? That would mean hijacking my own
localhost, surely? Which may not be nice to someone using my proposed
tool who happens to also have a local web server running on their dev
machine.

Thanks for you interest.

Regards,
Nicolas
 
C

Chris Shepherd

Nicolas said:
Perhaps is should have posted in a networking group? I don't follow how
it would help if my device supported the loopback interface. How would
it work it that case? Or rather, how does loopback support in the device
enable me to connect to it from my PC? (These questions are straying
off-topic but I am interested to understand better)

I think the misunderstanding was all mine. I was picturing the device as
a networked handheld/embedded system that would be locally configured,
not remotely.
Ok, I could basically perform the identical process from code. My only
question is whether there is a method to add the static arp entry from
code, or would I have to do it through a shell command?

A shell command would be simplest, but I would bet that Microsoft has
exposed the required API calls to do it. I've never had to do it, so I
couldn't tell you where to start unfortunately.
Again, my lack of understanding on the loopback interface, but why the
default address of 127.0.0.1? That would mean hijacking my own
localhost, surely? Which may not be nice to someone using my proposed
tool who happens to also have a local web server running on their dev
machine.

Well, this is where I failed to understand what you meant. For remotely
configuring it, I would definitely use a specific address on your range
(or small range of addresses) in the event that you will be
simultaneously configuring multiple of these devices on the same network.

Chris.
 
N

Nicolas Noakes

I think the misunderstanding was all mine. I was picturing the device as a
networked handheld/embedded system that would be locally configured, not
remotely.

Fine, that makes your comments much clearer! I want to write a utility to
run on a pc
A shell command would be simplest, but I would bet that Microsoft has
exposed the required API calls to do it. I've never had to do it, so I
couldn't tell you where to start unfortunately.

I'll carry on looking into it, thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top