Convert an IP address into an integer

Hi Everyone,
One of methods in my COM object is
public void setIP(Variant ip)
with Variant data type supposes to be 4 byte int. I don't know how to convert a string like "192.167.1.108" to an int so I can pass in the above function. Would anybody please help me out!
Someone helped me out with his sample, but for some reason, the sample did not work for all ip address. e.g 192.167.1.108, 192.167.2.1 etc.
Here is someone's sample:
static int ipToInt(String ip)
StringTokenizer st = new StringTokenizer(ip, ".");     
int numParts = st.countTokens();     
if (numParts == 0)          
throw new IllegalArgumentException("Invalid IP address: empty argument");     
if (numParts > 4)          
throw new IllegalArgumentException("Invalid IP address: too many tokens");     
int ipInt = 0;          
for (int i = 1; i < numParts; i++)     
String token = st.nextToken();          
int tokenVal = Integer.parseInt(token);          
// Above will throw NumberFormatException if the token is not an integer          
int processedVal = tokenVal << (8 * (4 - i));          
// Moves the byte to the correct portion of the int          
ipInt = ipInt + processedVal;     
String token = st.nextToken();     
int tokenVal = Integer.parseInt(token);     
// Above will throw NumberFormatException if the token is not an integer     
ipInt = ipInt + tokenVal;
Thanks in advance
Hung

static long ipToInt(String ip)
StringTokenizer st = new StringTokenizer(ip, ".");
long numParts = st.countTokens();
if (numParts == 0)
throw new IllegalArgumentException("Invalid IP address: empty argument");
if (numParts > 4)
throw new IllegalArgumentException("Invalid IP address: too many tokens");
long ipInt = 0;
while (st.hasMoreTokens()) {
long tokenVal = Integer.parseInt(st.nextToken());
ipInt = (ipInt << 8) + tokenVal;
// System.out.println(Long.toHexString(ipInt));
return ipInt;

Similar Messages

  • Converting email or web address into *****

    I am trying to convert email or web address into *****
    text=text.replaceAll(".com","*****");
    text=text.replaceAll(".net","*****");
    text=text.replaceAll(".org","*****");it replace .com and without com as well e.g. if there is company, network or organization it also change without caring dot?
              text1=text1.replaceAll("www","http://www");
              text1=text1.replaceAll("www1","http://www1");
              text1=text1.replaceAll("(?:ht|f)tp://\\S+(?<![!.?])", "<a href=\"#\" target=\"_blank\">*****</a>");but I can not control e.g. hotmail.com or yahoo.com or kkk.com
    is there any simple way to convert email or web address into *****
    thanks & regards

    farakh wrote:
    prometheuz wrote:
    Far from perfect to say the least (watch out for false positives!), but it might give you some new ideas:
            String text = "My e-mail address id [email protected] and you can find my "+
    "website at http://somesite.co.uk, ok?";
    String domainRegex = "[\\w]+(([.][\\w]+){1,2})";
    String emailRegex = "[\\w]+@"+domainRegex;
    String siteRegex = "(https?://)?(www[.])?"+domainRegex;
    text = text.replaceAll(emailRegex+"|"+siteRegex, "*****");
    System.out.println(text);Good luck.
    this code changes the following also that shouldn't be:
    SS201/202/304/316 tube.carbon pipe, fittings.
    converts SS201/202/304/316 ***** pipe, fittings.
    and how can v solve this problem?
    my website is yahoo dot com
    and my email is kk at hotmail dot com
    thanks & regardsLike I said: the code is far from perfect and will probably produce false positives (as you already mentioned). Try to play with it so that it suits your needs.

  • Is there an easy way to convert a long string into an array?

    I can convert a long string into a 1-d array by parsing and using build array, but I would like to know if there is a function to make this easier.
    For example:
    from/   aaaaaaaabbbbbbbbccccccccdddddddd         (string of ascii)
    to/       an array that is 1-d with each element having eight characters
              aaaaaaaa
              bbbbbbbb
              cccccccc
              dddddddd
    Thank you.
    Solved!
    Go to Solution.

    Try something like this:
    (If you can guarantee that the string length is an integer multiple of 8, you an drop the two triangular modes in the upper left. )
    Message Edited by altenbach on 03-14-2010 06:40 PM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    ChopString.png ‏9 KB

  • I previously has service.1)  What product allows me to digitally sign a PDF? ,2)  convert a word doc into PDF?

    I previously has service.1)  What product allows me to digitally sign a PDF? ,2)  convert a word doc into PDF?

    Hi robertb48724220,
    Are you using the same email address that you use here in the forums? That's how I looked up your account, and saw that you have a active subscription. You should be able to sign in with that email address and the associated password.
    Best,
    Sara

  • SharePoint 2013---How to convert current left Navigation into tree view

    Hi All,
    I want to convert current left navigation into tree view in SharePoint 2013. When we click on Modify Navigation and set headers and links; I need that should be convert into tree view. All headers should be expandable to thier links.
    I just want tree view on navigation headers and links. not for all site and subsites which we can enabled from site settings --> Modify All Site settings --> Tree view
    Please help me Master Page editing on Navigation Generation.. Thanks in advance!
    Regards,
    Anna

    Hi Anna,
    If you want to replace the Quick Launch part with the custom treeview web part in master page, you can comment out or remove the quick launch code block "<!--SPM:<SharePoint:SPNavigationManager id="QuickLaunchNavigationManager.....>....<>-->",
    then insert the custom web part snippet code in proper location in seattle master page, then all pages inheriting the seattle master page will have this web part.
    Note, please back up the master page before customizing the original master page for recovery.
    http://msdn.microsoft.com/en-us/library/office/jj862341(v=office.15).aspx
    http://www.sharepointpals.com/post/Add-snippets-in-Page-layout-using-design-manager
    Thanks,
    Daniel Yang
    Forum Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact [email protected] 
    Daniel Yang
    TechNet Community Support

  • HT3529 I have just bought an iPad I have typed in email addresses into Contacts, but when I try to send a message most of them come up within red with an !. Then it will not let me send! This is sapping my confidence ! Please help if possible!

    I have typed in email addresses into Contacts, but when I try to do an email, most of them have an exclamation mark and won't let me send! Where am I going wrong ? It is really sapping my confidence!

    Did you set up your email account info in Settings?
    Settings > Mail, Contacts, Calendar > Accounts > your account should be listed in there with the appropriate incoming and outgoing mail servers and correct user names and passwords.

  • How to convert a .class file into .java file without .jad using DeJDecompil

    Hi all,
    I am using DeJDecompiler and working with swing applications.If I try to convert a .class file into .java file,it is converting into .jad file only.Fine but if I try to save that file into .java file,It is giving lot of errors in that program.When I went into that program the total style of the program is changed and TRY-CATCH block is not recognised by the dejdecompiler,hence If I try to include some methods in the existing .java file thus got,I could not do.Kindly help me.
    If I get the .java file without error then I can process the rest of the functionality.
    Thanks in advance
    With kind Regs
    Satheesh.K

    Not so urgent today then!
    http://forum.java.sun.com/thread.jsp?thread=553576&forum=31&message=2709757
    I'm still not going to help you to steal someone�s code.

  • How can I convert a Java program into a screen saver ?

    I want to write a screen saver in Java, which is to be run under Window 95 platform. However, I don't know how to convert a .class file into a .scr file ?

    A SCR File is just an renamed exe file. So what you need is an CLASS2EXE converter (there are some around) and than simply rename the file to scr.
    Dont forget the special parameters scr files have, like /s or /c for config...look up in google for those.

  • How to add multiple e-mail addresses into my iPad Contacts?

    I just received an e-mail with 40 addresses in the distribution list. Now I want to add all of the addresses into my iPad Contacts. How can I do this in one operation rather doing each of the 40 addresses individually?

    Unfortunately you can't add all at once. But you save a lot of time by the copy/paste method (double-tap at a mail address, tap "copy", go to the "Contacts" app, enter the contact you want to paste the address in, tap "Mail address", then double tap again and tap "paste").

  • How can I create a link that allows users to convert a Wiki pages into PDF format.

    I am working on an enterprise Wiki library site collection, but I want to create a link named “Convert to PDF” , which allow users to convert the current Wiki into a pdf file. I need this link to be displayed some where in all the exsiting Wikis pages, and
    on any new wiki page. Can anyone advice if there is already such as capability within sharePoint 2013.
    Thanks

    Hi,
    For your requirement, we can add this link to the master page, then it will appear in the pages which apply this master page.
    To convert the current page to PDF, you can take consideration of using jsPDF.
    The links below with demos for your reference:
    http://parall.ax/products/jspdf
    Best regards
    Patrick Liang
    TechNet Community Support

  • How do I convert an ASP file into a PDF?

    How do I convert an ASP file into a PDF?

    None of the free Adobe Reader products (Adobe Reader Touch, Adobe Reader for iOS/Android, Adobe Reader XI for desktop) provide the support for converting ASP to PDF.
    Acrobat XI Pro and Standard (which are not free) can convert an ASP page into PDF.
    Please note that Acrobat XI Pro, Standard, and Reader XI are not compatible with the Windows RT operating system.

  • How do I convert an Excel file into a pdf?

    how do I convert an Excel file into a pdf?

    Hi tomduffey,
    You can either use Create pdf service or Adobe Acrobat software for the purpose.
    Please refer -
    Using Create PDF service : https://www.acrobat.com/createpdf/en_GB/convert-excel-to-pdf-converter.html
    Using Adobe Acrobat : http://wwwimages.adobe.com/www.adobe.com/content/dam/Adobe/en/products/acrobat/pdfs/adobe- acrobat-xi-create-pdf-files-tutorial-ue.pdf

  • How do I convert an Adobe file into a word document?

    How do I convert an Adobe file into a word document?

    What type of Adobe document are you trying to convert?  Which Adobe software or service are you utilizing?

  • Can i convert AIFF audio file into an MP3 file please?

    Can i convert AIFF audio file into an MP3 file please? I will be doing this on an imac 2008 model. thank you for help!

    Since this is the Logic forum and you may be working in Logic, you dont even need iTunes. To convert Aiff to MP3:
    1 - Go to the Bin>Audio Files
    2 - Select the Audio File you want to convert ( and not a region or edit of it)
    3 - Go to Audio File next to the Link icon ( Audio - Edit - View ) and down the menu to Copy/Convert.. gives lots of options
    HTAH
    (hope that also helps)
    MS

  • How do I convert an audio link into a wav file?

    how do I convert an audio link into a wav file with my Imac?
    A PC user showed me to right click an audio link where it asked if it wanted to save the link as a Wav file?
    I saw this done in front of me. How do I do it with my Mac ?

    This is how to do it in itunes http://support.apple.com/kb/ht1550
    If I view the song in finder, all that i have to do is press command-i and it opens a window. In the section where you view the name and extension I took off the extension (.mp3 in my case) and replaced it with .wav

Maybe you are looking for

  • I would like to send out email to a mailing list I put together. How do I do this?

    I would to send out a "special offer" to a small mailing list. I have created the list already. Obviously I want to send it as a BCC. How do I do this? Do I address it to myself first and in the following line BCC the Mailing List? I would appreciate

  • Garbled V-cards and headers in e-mail

    The header field in received e-mails is illegible. As well, the "V cards" in my address also are illegible: funny-looking, jammed up characters. I believe this problem is somehow connected to my address book. For the life of me I cannot figure out wh

  • My t61 - no power after changing the power jack

    Hello guys, So the long story short , the power jack on my t61 wasn't working.I bought the new one , changed it today , I am pluging it -no power at all.I dont think its the charger as up until the end it was working , its here to say i havent starte

  • 2 identical indexes but with different names - index load balancing?

    Hello, is it theoretically possible to have 2 indexes which differ only in their names? And make something like load balancing? The real situation that brought me to that question is that one of my indexes is sometimes unavailable and the queries tha

  • Touch screen stopped working with Safari.  Works fine with everything else.

    So, all of a sudden this morning my Touch will not work in Safari. I can go to web pages via the bookmark button but cannot highlight or type in any links. Doesn't recognize my incredibly gentle touch:) Anyone else with this problem? Cheers mrjazz