Everybody is absolutely dead on here. "How do you get a girlfriend"? By stopping perceiving yourself a "loner" and seeing yourself in a more positive way than "not a looker" and "not very smart" (these descriptions aren't very helpful because they are too general and simplistic to be of real use when describing yourself). By stepping out of a victim orientation and becoming more of an owner of your reality.
Neediness is very unattractive. Be careful, by the way, that you don't become 'needy' around the way you're perceived, either. Stop caring about how you're perceived and start thinking about what you're creating, what you're doing and what you're perceiving. For example: asking questions like 'is she perceiving me as confident right now?' is not going to serve you much at all. Shift your focus entirely to: 'what kind of relationship am I helping to create here?', 'what am I perceiving?' and so on. What I'm suggesting here is to flip your focus from being worried or needy about how others perceive you towards grounded in yourself and simply thinking about what you're creating and perceiving yourself.
The thing is, this change can't really just happen for girls; I'm not sure if that's possible and anyway it'd probably be a good idea to affect this change in your whole life anyway. Your whole social approach, sense of self and so on will develop if you choose to change your outlook and behaviour in this way; it will however take time and sustained effort and consciousness in order to become much more grounded and confident in yourself and not focusing / interested in the judgements of others all the time.
You're looking to be in a really good place psychologically before you create a relationship. A girlfriend can't "make you confident" directly. You can be influenced by having a girlfriend, but if you're interested in having the kind of relationship that is most fulfilling and satisfying, I would recommend entering into it from the best psychological state possible and not hoping that the girlfriend will somehow 'resolve' your failures (what an awful burden to cast on a girl - and a completely ridiculous one that she will not be able to fulfill because YOU are empowered to make the necessary changes here).