Muslim convert Gavin Rae, 36, was brought back to the UK in July 2015 along with his wife and children after being denied entry to Turkey, which neighbours war-torn Syria.
Four months later he was arrested by armed officers in a hotel room in Crewe, Cheshire, for attempting to buy pistols and machine guns in a police sting.
Jurors heard how construction worker Rae, who converted to Islam in 2012 and lived in north Preston, had been befriended by an undercover officer while working in Edinburgh.
At a hostel where he was staying, he met the operative “Tony” who posed as a fellow Muslim from Eastern Europe, Preston Crown Court heard.
Rae told his new friend: “It’s not gonna be long now before Islam will come to the shores of this country...and if they reject it we’ll fight them. But we want to live under sharia not democracy.”
He said of Britain: “It’s full of paedophiles, sex people. It’s horrible. Filthy mate. Filthy. Females, the women, the women are filthy you know. Disgusting.”
The defendant, who took the name Yaqub Rae, said authorities thought him a “danger to this country” and believed his intentions were to “go and join Isis and do jihad”, the court heard.
Within a week he told Tony that, once his family were in a Muslim country, he would “go then and sacrifice my life for Allah”.
When Rae began asking about getting his hands on weapons, Tony said he had a contact, Hamza, who could source them.
Hamza, also an undercover operative, met the defendant at retail park Bicester Village, near Oxford, near where Rae was then working.
He told the defendant he knew someone called Vik, who could convert de-activated weapons, citing a price of £850 for one gun.
A meeting was set up for November 3 last year at a Travelodge near Crewe where Vik was waiting with weapons to handover to Rae and Hamza.
Rae was shown a Baikal gun, which had been deactivated, along with ammunition and a silencer.
The defendant asked for more ammunition and asked Vik if he could also get hold of an Uzi machine gun, adding: “Can you do shotguns?”
But after the cash and gun were exchanged, armed police burst in to arrest Rae.
The defendant joined the King’s Division of the British Army in February 1997 but was discharged 14 months later without going on operations.
He had been convicted in 2004 of four robberies of betting shops in Manchester using an imitation handgun.
Last month, Rae, originally from Preston, was found guilty of possessing the Baikal gun with intent to endanger life and attempting to possess ammunition.
He was also convicted on three counts of encouraging or assisting the commission of an offence by trying to get “Vik” to source a Glock gun, Uzi and ammunition.
In a letter written to Mr Justice Sweeney ahead of his sentencing, Rae expressed “regret and shame” for what he did.
The court heard he continued to deny intending to take his family to Syria.
The judge sentenced Rae at the Old Bailey to 18 years in jail with a further five years on extended licence.
He told him: “I am sure that as the prosecution alleged throughout your trial, you decided to gain possession of working firearms and a quantity of ammunition so that if it became in your view necessary you could use them to enable you to take the children from this country by force and go on to take part in fighting abroad in support of the extremist Islamic ideas that you espoused in a number of recordings by undercover officers.”
The judge told Rae that he had been convicted on “overwhelming evidence” and he had no doubt that he was a dangerous offender.
Throughout the hearing, Rae, who appeared via video link from Manchester, wept with his head buried in his hand.