free swedish number portability look up service

When Sweden implemented number portability for mobiles (MNP – Mobile Number Portability) and fixed lines there where some people who stated that this information should be published in DNS or a DNS like system so it would be cheap and available for everyone to use. Naturally the telcos wanted to do it the way they always did things. With a centralized fat solution.

So Sweden ended up with a Oracle based central database (CRDB) solution system implemented by Cap Gemini and Oracle. This system is now run by SNPAC AB (Owned by Swedens large telcos) who charges approx. 19200 Euros to connect and 14400 Euros per year. Which really is out of the reach for small scale actors on the market or hobbyists running an Asterisk pbx that would like to do choose the cheapest route to place a call.

The other day the Swedish PTS (The Swedish Post and Telecom Agency) launched a web page where you could check which operator was terminating which number. So i decided to go ahead and implement a DNS based look up method.

First a little rant about their service. Well it is nice that they offer different interfaces, today they support SOAP 1.1, SOAP 1.2, HTTP GET and HTTP POST. But why should the end user have to care about dividing the into NDC and SN?  (NDC – National Destination Code and SN – Subscriber Number) after all the PTS is authorative of the NDC’s so why couldn’t they split the number for us? And why not a whole MSISDN (Mobile Subscriber Integrated Services Digital Network Number) or why not a whole E.164 number? Or what about actually implementing a ENUM (E.164 NUmber Mapping) look up?

Ok enough rant. I had a couple of hours over so i sat down with a FreeBSD box and pwerdns and started to code. So now i (and the rest of the world) can do the following lookups with their favorite DNS tool:

% dig TXT

% dig TXT

The result is a string containing the name of the operator handling the number. (I have included a full output below) Not the best reply to do automatic call routing but good enough as a proof of concept implementation of bridging DNS and MNP database. Right now i’m implementing a ENUM type so you could automatically integrate this into your Asterisk PBX and choose the best outgoing line for your calls. Since operators often have “Call free within our network” deals this would be a great tool for low cost routing of your phone calls.

But before starting to implementing stuff using this a couple of notes:

  • This is an experiment.
  • I have not fully tuned caching and performance yet.
  • I currently only support the follwing NDC’s: 8, 31, 40, 70, 72, 73, 76 (Swedens 3 biggest cities and the GSM and 3G networks) More NDC’s will follow when i have found a machine readable list so i don’t have to type them all in…

So a couple questions to you reading this:

  • Would you like this as a permanent service?
  • Any other useful stuff you want to look up over DNS?
  • Which information would you like returned in the  ENUM? (I’m especially interested in the needs of non Asterisk users.)

Please give me some feedback below and i will try to take your ideas into consideration.

A full example of a search using dig:

% dig txt
; <<>> DiG 9.6.1-P2 <<>> txt

;; global options: +cmd

;; Got answer:

;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 57824

;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0


;; ANSWER SECTION: 3600 IN TXT “Telenor Sverige AB”

;; Query time: 39 msec


;; WHEN: Sat Aug 20 13:44:06 2011

;; MSG SIZE  rcvd: 72


  1. 5 Responses to “free swedish number portability look up service”

  2. Cool!

    Couldn’t you do some copy/paste from the lists here?över_svenska_riktnummer

    By Hugo on Aug 20, 2011

  3. Well that list missed some NDC’s that i found in PTS documentation. (NDC’s are not only area codes.) But i found a list that i now have implemented.

    So now i think most of the Swedish area codes will work.

    I just need to study some nice corner cases before i’m 100% sure…

    By admin on Aug 21, 2011

  4. Splendid! I’d like to use it personally to know if the mobile call to a friend will be free (if same operator). I doubt I will get time to build such application – or mobile app but maybe I’ll make some dns lookups.

    By Stefan Pettersson on Aug 21, 2011

  5. This now works for all Swedish NDC’s (areacodes in layman terms.)

    By admin on Oct 2, 2011

  6. Hi

    How do one use this? What if i want to make a website where users can lookup numbers and see the operator? Is there a open WebService provided by PTS? or anyone else?

    By Adnan Khan on Nov 24, 2011

Post a Comment