Broadly speaking, you are asking how a chemist knows what a given substance is. In the modern day, we have several instruments that provide spectroscopic data that helps identify the structure of a substance. It should be noted that this depends on the purpose of the investigation. For example, if we simply wish to check that the substance is what it is claimed to be, then one can simply compare a spectrum of the unknown with a spectrum of a known sample. The spectrum itself need not provide much information about the structure because all one needs is that the two spectra be the same, like comparing fingerprints. By contrast, if the substance is truly unknown, then one would choose spectroscopic data that provides useful information about the structure. And different instruments provide different information about different aspects of the structure. For example, a low-resolution mass spectrum tells one the molecular mass of the substance. A high-resolution mass spectrum tells one the molecular formula of the substance. A proton nuclear magnetic resonance spectrum provides information about the environment of each hydrogen atom in the molecule, including couplings to adjacent hydrogen atoms. X-ray crystallography provides what is more or less an actual picture of the molecule, including precise bond lengths and bond angles (though this does require a good quality single crystal of the substance, and substantial computer processing of the diffraction data, and may not provide a complete picture). There is of course a lot more that could be said, but I think the above provides a glimpse into the world of the working chemist.