Home AMX User Forum NetLinx Studio

get IP + MAC address from Socket connection

Is there a way to obtain the IP address and MAC address from a socket connection to a server device?

Obviously I have to already know the IP address in order to connect to it, but it would still be handy to programmatically query these connection properties, especially MAC address.

Sam

Comments

  • ericmedleyericmedley Posts: 4,177
    You can get the ip address at least from the data_event. But, I'm not sure if it works for ip_client_open. I've only used it when the port on the AMX master is the server.

    this from the help file...
    Property Name
    Type
    Description

    Data.SourceIP
    CHAR Array
    IP address of the client/source application

    Data.SourcePort
    LONG
    Server/source port number


    We cannot access data from that layer in an IP conversation from within code. But you might be able to cobble together a SNMP message to request the MAC if SNMP is enabled on the device you're hitting.
  • a_riot42a_riot42 Posts: 1,624
    You could cobble an ARP packet if Netlinx used raw sockets, but as far as I know there is no access to raw sockets in Netlinx, only through TCP or UDP. So an alternative would be to try and talk to the switch or router if has an API that is accessible from Netlinx. Not sure why you would need to short circuit the ARP tables though. The only other thing I can think of is if Java has access to raw sockets, or there is library to do so. I kind of doubt that the version running on Netlinx has such a thing. I've written a bunch of networking code in C dealing with raw sockets, and while very interesting, you have to know the protocols inside and out, and that takes a while. Its great to do it once though and get a good feel for what's going on under the covers. I wrote an SFTP client/server in C a long time ago, and it was great fun to do, but I was in school, not trying to make a profit. If you figure out a way, post how you did it. This could come in handy for spoofing MAC addresses and getting around streaming services blockades :)
    Paul
  • ericmedleyericmedley Posts: 4,177
    Once I kinda made a ping from code by deliberately (sorta) blowing the stack by making a message that filled out the full layer 2 message, thus fooling the remote box into thinking the IP packet was finished and then tagging a ping request string on the next section and then a dummy end tag that would, of course, just error out. It worked in that the box did try to respond. But the AMX master couldn't really report the ping return.

    Pretty useless but I did have a couple hours of programming fun.
  • a_riot42a_riot42 Posts: 1,624
    It sure would be nice if we could execute shell commands in Netlinx. Maybe the new boxes will allow something like that.
    Paul
  • ericmedleyericmedley Posts: 4,177
    I think once we get up to full-bore JAVA a lot of this kind of stuff will go away.
  • a_riot42a_riot42 Posts: 1,624
    ericmedley wrote: »
    I think once we get up to full-bore JAVA a lot of this kind of stuff will go away.

    I wish we could inject Java code into Netlinx code with a delimiter similar to the way you can inject Java code into HTML with JSP. That would have been easier than dealing with Duet modules, and all the ancillary stuff.
    Paul
  • ericmedleyericmedley Posts: 4,177
    a_riot42 wrote: »
    I wish we could inject Java code into Netlinx code with a delimiter similar to the way you can inject Java code into HTML with JSP. That would have been easier than dealing with Duet modules, and all the ancillary stuff.
    Paul

    Oh geez yes!
  • a_riot42a_riot42 Posts: 1,624
    ericmedley wrote: »
    Oh geez yes!

    Then the JVM loads if it finds the delimiter in the Netlinx code at compile time, and doesn't if it doesn't. You can still have lightweight Netlinx programs, but can include Java should you need more library functions. Instead of loading Duet modules separately, you would just have Netlinx modules that might include or be completely comprised of Java code. I'm a hopeless dreamer, I know.
    Paul
Sign In or Register to comment.