apprentice has asked for the wisdom of the Perl Monks concerning the following question:

I need to write a test program for a product my company is developing. The program needs to simulate multiple machines not just by using multiple IP addresses, but also multiple MAC addresses. I've looked through Network Programming with Perl to no avail. Can anyone point me in the right direction? Is it possible in perl? I can use Linux or various flavors of win32.

Thanks for any help!
  • Comment on How can I simulate multiple IP/MAC combinations on one computer?

Replies are listed 'Best First'.
Re: How can I simulate multiple IP/MAC combinations on one computer?
by Vavoom (Scribe) on Oct 20, 2001 at 00:28 UTC
    Since MAC addresses are a hardware level feature, the answer will depend on the NIC you are using and whether it supports multiple MAC addresses. The interface used to do this would also be vendor specific.

    As for multiple IP addresses, this would typically be an OS-level issue, rather than an application-level issue. Once you have configured your OS with multiple IPs, it should be fairly straight forward to connect to them individually from your application as needed.

    Vavoom
Re: How can I simulate multiple IP/MAC combinations on one computer?
by no_slogan (Deacon) on Oct 20, 2001 at 01:16 UTC
    Try this: Net::RawIP

    You can kludge up packets that have pretty much arbitrary header fields, and turn them loose on the network. How well this works for you is probably operating-system dependent.

Re: How can I simulate multiple IP/MAC combinations on one computer?
by IraTarball (Monk) on Oct 20, 2001 at 01:34 UTC
    Warning, this is stream of conciousness, untested and not approved by the FDA for general use on humans.

    You might be able to simulate this by putting your NIC in promiscuous mode and sniffing for the packets with the multiple MAC addresses you want. A quick search on CPAN seems to show a number of modules to impliment a TCP/IP stack so one might actually be able to pull something like this off. You've got to fake out the routers, and since MAC addresses need to be unique, you could, however unlikely, colide. It sounds like a bit of an undertaking to me. But it's the only thing I can think of that might come close to what you're looking for.
    Good luck though.

    Ira,

    "So... What do all these little arrows mean?"
    ~unknown

Re: How can I simulate multiple IP/MAC combinations on one computer?
by FoxtrotUniform (Prior) on Oct 20, 2001 at 07:57 UTC

    I'm surprised nobody's mentioned the magic letters that make all the difference when dealing with MAC addresses: A, R, and P. (Address Resolution Protocol.)

    Disclaimer: networking isn't my field. Take this node with a pillar of salt.

    ARP is used on Ethernet networks to map between 32-bit IP (Internet) addresses and 48-bit MAC (hardware) addresses; it's how the router figures out that, hey, 209.foo.bar.baz is this computer, not that one. The short version, IIRC, is that the router, upon receiving a packet to 209.foo.bar.baz, broadcasts an ARP packet to its local Ethernet, saying "Hey, which network interface is 209.foo.bar.baz?" The appropriate computer is supposed to reply with another ARP packet, saying "I am, and my MAC address is 00:00:aa:bb:cc:dd" The router caches that MAC address, and sends all packets addressed to 209.foo.bar.baz to the local MAC 00:00:aa:bb:cc:dd.

    (I think. I'm skimming TCP/IP Illustrated vol. 1 as I write this, but there's no guarantee that I'm properly interpreting everything.)

    So to spoof a MAC address, you need to come up with the "Hey, I'm 209.foo.bar.baz" packet on the local net. The problem is, ARP is usually handled by the network card driver. On the other hand, you may be able to hook into a firewall/packet filtering program to spoof ARP packets.

    ARP is described in RFC 826.

    Of course, all this really lets you do is spoof multiple IPs from a single MAC address. To set MAC addresses, I direct you to the arp(8) man page on 4.3BSD and later Unix systems, or to Google for others. (There seems to be an arp command on Windows 2000, according to my Google search; not having Win2k, I wouldn't know.)

    I suspect that it's easier to make system calls (to such beasts as ifconfig and arp) inside a Perl script than it is to forge packets and mung hardware MAC addresses via Perl modules.

    --
    :wq
Re: How can I simulate multiple IP/MAC combinations on one computer?
by traveler (Parson) on Oct 20, 2001 at 03:07 UTC
    On linux you can have multiple IPs per physical device. You can create a virtual Ethernet interface on eth0 with ifconfig eth0:1 10.1.1.1 netmask 255.255.255.0, for example. You can sometimes set the hardware address with ifconfig, too, but it depends on whether or not your driver allows the SIOCSIFHWADDR ioctl. Or you can use the ioctl in perl like this (untested):
    require "ioctl.ph"; use Fcntl; ... sysopen ETHER, "/dev/your-ethernet-device", O_RDONLY; # You'll need to pack the address into $addr. ioctl ETHER, &SIOCSIFHWADDR, $addr;
    You might check out libnet which is a tool for building packets. You could probably build the xs files. The libnet on CPAN is not the same thing. You could also try some hacker sites as they use such techniques for attacking systems...

    W2k lets you set multiple IP addresses on an interface, too, but I don't know how to refer to them in a program. HTH, --traveler