Quickie answer:
For a quick test, if you can slice off a small piece of the suspect material and heat it to a nice glowing red that a magnet won't stick to then let cool in still air. D2 tends to need an inert atmosphere for pro grade heat treat but don't sweat it for this. Once cool, if a file skates over the material, it's A2, D2, or some other air cooling tool steel. If it cuts, maybe with some effort, it's probably 4140 or some other low carbon steel. 4140 requires quenching so will be almost completely annealed when allowed to slowly cool in air. Brush off any scale before trying the file, scale tends to be silly hard on almost all steels.
Details for the metallurgically curious:
D2 is an air hardening steel. It is often used in die fabrication as it is very wear resistant. It holds a good edge in places where you need an edge (knives, some dies), but isn't very tough. It will chip fairly easily under a hard impact. Lovely for a small knife, pretty lousy for a camp ax, hammer, or large framing chisel. It's sort of like A2 in working characteristics.
D2 has higher carbon, vanadium, and chromium than A2, and lower manganese. Both steel have overlapping ranges for silicon and molybdenum.
D2 is stronger, polishes better, wears better, and corrodes less compared to A2. A2 is tougher. I like A2 for things like shop made gear cutters and fly cutters, where the cutting edges sees a lot of impact in use.
4140 is a low alloy steel, very tough, hardness maxes out around 58C in theory, although most charts show it maxing out at around 40C. Prehard is usually delivered at around 30C hardness. I've seen it used in firearms receivers, where you want need to balance wear resistance and toughness, but don't need a high hardness knife sharp edge for cutting or shearing. 4140 is a good steel for forging, and tends to behave nicely when quenching, unlike some stuff that wants to turn into a pretzel when it hits the quench. It has around 1 percent manganese and chromium, around 0.25% molybdenum.
These are all nice steels, but as you suspect, they are each quite different animals.
Maybe more than you wanted to know!
Cheers,
Stan