Is there an API that sorts computers into already created groups?

Hi,

I am looking to see if there is an API that will allow me to move machines into already created groups. We have around 40 different offices ,each with different IP addresses, that need to be sorted into their perspective groups. I have an install scripts that will do it, but we have a good number of machines that did not move into the groups. Any help is appreciated.

Thanks!!!