IPv6 link-local address format - windows

I am working on a project related to networking/compression. One of the machines is Windows Vista, which already has IPv6 configured.
When I try ipconfig, I see an address in the following format: fe80::9dc8:72fa:aacd:76e2%10
But when I try to ping this machine from another with ping fe80::9dc8:72fa:aacd:76e2%10, I get the following error:
Ping request could not find host fe80::9dc8:72fa:e327:76e2%10.
Please check the name and try again.
Any ideas/comments are very helpful.

The %10 after the address is called the scope zone. When you use link-local IPv6 addresses, the scope zone is required so that the system knows which interface to send the packet out on.
On Windows, if you issue the netsh interface ipv6 show addresses command, you'll see the addresses assigned to the system complete with their zone IDs. Notice that the zone IDs match the interface index. For example:
Interface 22: VirtualBox Host-Only Network
Addr Type DAD State Valid Life Pref. Life Address
--------- ----------- ---------- ---------- ------------------------
Other Preferred infinite infinite fe80::15c3:6bea:aaac:a015%22
This address is scoped %22 because it is on an interface whose index is 22. Similarly, on Linux, you might see a link-local address like fe80::15c3:6bea:aaac:a016%eth0. The format of the zone ID is unique to each individual machine running IPv6, which is why it might be different if you try the ping from the other system.
For example, if you have:
System A (Windows): fe80::15c3:6bea:aaac:a015%22
System B (Linux): fe80::15c3:6bea:aaac:a016%eth0
... and you want to ping the Linux box from the Windows box, you cannot do ping fe80::15c3:6bea:aaac:a016%eth0. But you can do ping fe80::15c3:6bea:aaac:a016%22. This is the problem. Link-local addresses can be tricky in this way.
Try specifying the correct zone ID. That is, when you do your ping fe80::9dc8:72fa:aacd:76e2%10, first do netsh interface ipv6 show addresses on the machine you are pinging from, and change the %10 to the interface index for whichever interface you want to use on the source system.
If the machine you are pinging from is Linux, you will have to do ping6 -I eth0 fe80::9dc8:72fa:aacd:76e2 (assuming the other system is on eth0), because the Linux command-line utility does not support the % way of specifying the zone (the last time I checked, anyway).
Ideally you should set up an IPv6-capable router on your network to do router advertisements, so that you can use stateless address auto-configuration (SLAAC) and get global unicast addresses. Then this will not be an issue.

you cannot ping ipv6 addresses with the classic ping utility, only ipv4 addresses. linux has a commandline tool called ping6 to ping ipv6 addresses, windows probably has something similar. a little research told me that windows uses ping -6 for pinging ipv6 addresses.

The number after % is the interface name. if you open the status->detail of your network interface, you will see the ipv6 link-local address, with the %xx at the end of the address, which is the index of the interface, in case you want to find the index for some application. The System Information or ipconfig might just give you different index numbers, at least on my Windows 7 Pro, which is very confusing. The description you get from the OS could also be wrong.

Related

Getting MAC Address of devices using Local Network IP Address(192.168.xxx.xxx)

I am building a Mini-Project and I came across this problem..I have to find MAC Addresses of all Devices that were in my Home Network .Here I got all the devices local IP addresses (I pinged from 1 to 255 and noted down all responded devices IP's).Here i am using Windows with python 2.7.x .I do also need the Network Card Manufacturer Name.
In other words I just want the raw data that the WI-FI Watcher shows.
My aim to get MAC and Network Card Manufacturer Name
First of all please make sure you ping all the hosts in your subnet. I would ping the broadcast address first, then just in case all of them, maybe some of them did not respond to your broadcast.
This way you will fill the local ARP cache of your machine. Then you can run this executable:
arp -a -v
Which will output information on all the IP addresses and their corresponding MAC address.
Then it's just a matter of looking up the OUI of the MAC address.
In pure python, as you mention in your comment, you can use "Scapy". you can find an ARP ping example here:
https://freezion.com/2009/01/22/arp-ping-using-scapy/
Basically:
from scapy import srp,Ether,ARP,conf
conf.verb=0
ans,unans=srp(Ether(dst="ff:ff:ff:ff:ff:ff")/ARP(pdst=sys.argv[1]),
timeout=2)
For OUI lookup, you can use this small bit of code, although it has an external dependency:
import requests
for addr in ['88:53:2E:67:07:BE', 'FC:FB:FB:01:FA:21',
'D4:F4:6F:C9:EF:8D', '23:45:67']:
vendor = requests.get('http://api.macvendors.com/' + addr).text
print(addr, vendor)
Also, you can try the OUI parser lib from Wireshark.
NOTE: this does not work if ICMP is disabled on the destination hosts, in that case you have to run a traditional portscan and find open ports.

Finding MacAddress from IP Address in a platform independent way

I need to findout the mac address of the device from which my device gets TCP requests, I ll be getting the ip address of the device by tcp endpoint but i need to find out the mac address of the device.My application will be running on both windows and linux, so please suggest me a cross platform method to find the mac address.. Any boost libraries will help me doing the same??
Firstly, you can't find the MAC address for any network interface that is not on the same local area network. That information is not transmitted beyond the router.
There is a command line tool called arp that is available on Unix and also Windows that will list IP addresses and MAC addresses of interfaces that have been in communication with your PC. i.e.
arp -a
on Windows gives something like:
Interface: 9.175.198.236 --- 0x2
Internet Address Physical Address Type
9.175.198.129 00-1b-53-46-fa-7f dynamic
and on a Unix-alike looks like:
foo.bar.com (10.27.68.72) at 00:50:56:AE:00:0B [ether] on eth0
baz.bar.com (10.27.68.77) at 00:50:56:AE:00:10 [ether] on eth0
? (10.27.68.1) at 00:50:5A:1B:44:01 [ether] on eth0
You can try invoking it and parsing the output programmatically.
arp source code is available in the below link, take the piece of code that interests you! It is c code so it should work fine.
http://www.opensource.apple.com/source/network_cmds/network_cmds-328/arp.tproj/arp.c
First thing to note is that at TCP layer, you don't know the MAC addresses.
For your case, I guess you can do two things:
use arp or write a piece of code similar to arp which looks for MAC given the IP address.
The problem with this approach is that it won't work in cases when the source is in another network.
write your server in such a way that it requests for this information from the client sending TCP request. This can be done post TCP establishment. The client should also be able to look up the machine's MAC address for the given IP.

Find IP address of directly connected device

Is there a way to find out the IP address of a device that is directly connected to a specific ethernet interface? I.e. given one host, one wired ethernet connection and one second host connected to this wired connection, which layer or protocol below IP could be used to find this out.
I would also be comfortable with a Windows-only solution using some Windows-API function or callback.
(I know that the real way to do this would probably via DHCP, but this is about discovering a legacy device.)
Mmh ... there are many ways.
I answer another network discovery question, and I write a little getting started.
Some tcpip stacks reply to icmp broadcasts.
So you can try a PING to your network broadcast address.
For example, you have ip 192.168.1.1 and subnet 255.255.255.0
ping 192.168.1.255
stop the ping after 5 seconds
watch the devices replies : arp -a
Note : on step 3. you get the lists of the MAC-to-IP cached entries, so there are also the hosts in your subnet you exchange data to in the last minutes, even if they don't reply to icmp_get.
Note (2) : now I am on linux. I am not sure, but it can be windows doesn't reply to icm_get via broadcast.
Is it the only one device attached to your pc ?
Is it a router or another simple pc ?
To use DHCP, you'd have to run a DHCP server on the primary and a client on the secondary; the primary could then query the server to find out what address it handed out. Probably overkill.
I can't help you with Windows directly. On Unix, the "arp" command will tell you what IP addresses are known to be attached to the local ethernet segment. Windows will have this same information (since it's a core part of the IP/Ethernet interface) but I don't know how you get at it.
Of course, the networking stack will only know about the other host if it has previously seen traffic from it. You may have to first send a broadcast packet on the interface to elicit some sort of response and thus populate the local ARP table.
Windows 7 has the arp command within it.
arp -a should show you the static and dynamic type interfaces connected to your system.
Your Best Approach is to install Wireshark, reboot the device wait for the TCP/UDP stream , broadcasts will announce the IP address for both Ethernet ports
This is especially useful when the device connected does not have DHCP Client enabled, then you can go from there.
You can also get information from directly connected networking devices, such as network switches with LDWin, a portable and free Windows program published on github:
http://www.sysadmit.com/2016/11/windows-como-saber-la-ip-del-switch-al-que-estoy-conectado.html
LDWin supports the following methods of link discovery: CDP (Cisco Discovery Protocol) and LLDP (Link Layer Discovery Protocol).
You can obtain the model, management IP, VLAN identifier, Port identifier, firmware version, etc.

bind () to an IPv6 address in windows 7 is Failing with Error code :: WSAEADDRNOTAVAIL (10049)

I am trying to set-up a private ipv6 network with two windows-7 machines for tesing my application. I have written a sample code to test the socket apis. I have created an IPv6 socket. When I try to bind with the link-local address (which I get from ipconfig command), the error code is 10049.
Please inform, why the bind with Ipv6 address is failing in windows-7 machine ?
If you're using a link-local IPv6 address, you probably need to set the sin6_scope_id field in your sockaddr_in6 structure to indicate which interface you want to listen on. A link-local address is ambiguous, since every interface must have a link-local address assigned, and they all use the same prefix. (fe80::/64)
You should probably bind() your listen socket to the unspecified address (all-zeroes or ::) so this isn't an issue, but it will still be a problem for the sending side. If you don't specify the sin6_scope_id, the system won't know which interface to send the packet on.
To avoid the issue, it would be best to set up an IPv6 router that does router advertisements, so you can get global unicast (or, at a minimum, unique local) addresses.

How to detect if a windows machine is running IPV4 or IPV6?

Is there anyway to determine if a windows computer is running IPV6 using native utilities, python or php?
This is how I solved the issue, by trying to open up an IPv6 socket. If the system did not throw an error, then it is using IPv6.
import socket
def isIPV6():
ipv6 = True
try:
s = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
except:
ipv6 = False
return ipv6
Sure. If ipconfig contains an IPv6 Address entry for a real interface, you've probably got IPv6 connectivity. There are also useful registry entries at HKLM\SYSTEM\CurrentControlSet\services\TCPIP6.
Every computer ships with IPv4 at standard. IPv6 is only enabled on specific machines. But if you parse ifconfig/ipconfig then you should find yourself a IPv4/6 address in the output
Enumerate the interfaces and check for an IPv6 address, like everyone else has stated. Alternatives include trying to open an IPv6 socket or get Python to call WSCEnumProtocols()
Jakob's approach is the simplest; you could pipe the result and do a match to see whether a network adapter has a valid IPv6 address.
Additionally, you could get this by fetching the Windows Management Instrumentation class Win32_NetworkAdapterConfiguration. The property IPAddress is an array of all the IP addresses associated with a network adapter and you can match against them to see if there is a IPv6 address associated. But PS is a bit of an overkill, I'd go with Jakob's or Wyatt's answer unless you'd need to do something more intelligible and fancy (send an HTTP request; change some network rules; restart a service).

Resources