A DNA test is the only way to know in this case. They can perform this before birth but there's a risk that you could miscarry. It could be your boyfriend's but it could equally be your ex boyfriend's baby even if he pulled out.
I agree with worriedbabe. Either guy could be the father. You should defiantly tell your boyfriend now, before its too late. How would you like it if he cheated on you and possibly got another girl pregnant, and never told you! It would hurt deeply! So its better to get it out in the open to both men, before its too late. And get check for stds cause those can come to with any unprotected sex with partners back and forth. Its for your health, baby's and the ex, and your boyfriend. I know you said it would kill your boyfriend if he fount out, but not to judge you or anything, but didn't you think about that when you were laying down with your ex. Temptation is awful! And sometimes it gets the best of us, but remember there is always a consequence to everything. I wish you the best of luck.
sorry, it could be either man who is the father. you have made a big mistake, which you're aware of. a baby is the nicest thing you get from unprotected sex...you may also have got an sti. and may have passed it on to your boyfriend. i know none of this is what you want to hear, but it's all true. personally i would tell the bf, but that isa very personal decision that only you can make. i'd also get screened for stis. only you can decide whether on not you keep this baby. dna tests can be done in the womb ( 1% chance of miscarriage ) or after birth. i'm sorry, that is the only way you can know for sure in this case.