Get subnet mask to variable

Home Forums Scripting DOS Command Shell Get subnet mask to variable

This topic contains 3 replies, has 3 voices, and was last updated by Avatar dalesnail 4 years, 3 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • Avatar
    confuseis
    Participant
    #165727

    Hi

    To cut a long story short I need to get just the subnet mask on its own to a variable I can use in DOS

    I can get the ip address on its own but need the mask also I need to feed these values to other parts of the batch file

    How would I even display the mask on its own? I have searched about and nearest I came was the netsh command.

    I need to isolate the subnet mask.

    Hope someone has a idea?

    Thanks

    Confuseis

    JeremyW
    JeremyW
    Moderator
    #271375

    You mention DOS but are you really using DOS or are you using another operating system? What OS are you using?

    Avatar
    dalesnail
    Member
    #383879

    Hi Its Windows 7 OS I have found the answer in the meantime. In case anyone is interested I have included it below
    for /f “tokens=2,* delims=:” %%A in (‘ipconfig ^| find “Subnet”‘) do set subnet=%%A set subnet=%subnet:~1% echo %subnet% Thanks Confuseis

    JeremyW
    JeremyW
    Moderator
    #271379

    Thanks for sharing!

    For anyone that needs it, here it is in the code tags:
    for /f “tokens=2,* delims=:” %%A in (‘ipconfig ^| find “Subnet”‘) do set subnet=%%A
    set subnet=%subnet:~1%
    echo %subnet%
    [/CODE][CODE]for /f “tokens=2,* delims=:” %%A in (‘ipconfig ^| find “Subnet”‘) do set subnet=%%A
    set subnet=%subnet:~1%
    echo %subnet%
    [/CODE]

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.