In the ultimate case, a "board" is not something you can determine programmatically in software; it's not possible in general to tell if, e.g., a particular pin on the microcontroller is connected to a corresponding head pin on the board.
That said, as Edgar Bonet point out, the Arduino board definitions used in the IDE will generally do what you want. Just keep in mind, these are just someone saying "the board should be like this"; a cheap clone board, for example, might be different without a new and proper board definition.
With running code on the microcontroller itself, examining what it can see of the board, you can usually tell which microcontroller you're using. But that just tells you about the chip and its pins, and not about where leads from those pins might go. It sounds to me as if you're asking to find a way to see if your particular microcontroller (e.g., an ATmega328P) is on, say, an Arduino Uno or some other board where certain MCU pins may or may not be hooked up to board pins. The MCU can't tell whether any of its particular pins are connected to headers on the board. As a more specific example, someone could build a board with an MCU with 100 digital IO pins available, yet if only ten of these are brought out to pins on the board, the others are not easily usable.
uino.cc/en/Main/ArduinoBoardUno) or [Arduino Nano]
For your application, you're thinking in a good direction when considering how to make things easier for others using your code. However, I'd suggest that in the long run it's better just to have clear definitions in an obvious place in your sketch (at the top of the file in a single-file sketch, perhaps in a config.ino
in a multi-file sketch, or passed in to an initialization function for a library) that says explicitly what pins are used and is easy to change for others. Having the default pins used by the sketch move around if I load the sketch on a different board strikes me as rather confusing.
Keep in mind your audience: the people who are going to be using this on a board different from yours are Arduino hobbyists, and so they're already (or will soon become :-P) familiar with the idea of pins, pin definitions in code, and pin conflicts.