Raidri is mostly right, but there is a way to see which will and which wont attack you. If you are using the default Unit frames or default name plates the background/name plate color will tell you certain things:
Red: Hostile will attack you when you come to his aggro range
Yellow: Neutral will not attack unless you attack him/her/it
Green: Friendly will not attack you.
Blue: A friendly player
Orange: Due to your current reputation standing with a certain faction he currently
will attack you, but given you improve your reputation with given faction will
turn yellow and then green.
Those are the most common ones and I cannot recall any other colors right now. Also most tooltip addons and default will show the name in color regarding hostility.
Tooltip of Friendly npc:
Here is a picture I found on google demonstrating how it shows up on nameplates:
As you see the yaungol are red = will attack you when you reach aggro range and the turtle is yellow = will only defend if you attack.
E: Neutral cities(Shattrath and Dalaran) are areas known as sanctuaries which are exceptions here is what Nate wrote regarding the subject.
Nate Kerkhofs wrote:
Dalaran is indeed a neutral city, and ALSO a sanctuary, which means that there is no player versus player combat possible (opposite faction NPCs are included in PvP combat). There are some quests that require you to kill NPCs in certain sanctuaries, but you cannot attack the opposite faciton in a sanctuary. Mouse over the target: if you get a sword, they'll attack you. If you get something else, they'll ignore you, since you can't attack them back and it would be incredibly unfair for them to attack you.